pandas 删除熊猫数据框上的索引和列

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/50303300/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 05:33:17  来源:igfitidea点击:

Remove Index and columns on pandas dataframe

pythonpandas

提问by Shubham Kuse

I have this list:

我有这个清单:

import pandas as pd
l = [[1,2,3],[4,5,6],[7,8,9]]
New_dataframe = pd.DataFrame(l)
print(New_dataframe)

Output:

输出:

   0  1  2
0  1  2  3
1  4  5  6
2  7  8  9

I want to remove those indexed rows and columns. How to achieve that??DataFrame I would like to see is this:

我想删除那些索引的行和列。如何实现?我想看到的DataFrame是这样的:

1  2  3
4  5  6
7  8  9

How to remove that index column and rows??

如何删除该索引列和行?

采纳答案by jezrael

If want see only values is possible convert to 2d numpy array:

如果只想查看值可以转换为2d numpy array

print (New_dataframe.values)
[[1 2 3]
 [4 5 6]
 [7 8 9]]

If need see DataFrameit is possible by:

如果需要DataFrame,可以通过以下方式查看:

print (New_dataframe.to_csv(index=False, header=None, sep=' '))
1 2 3
4 5 6
7 8 9

print (New_dataframe.to_string(index=False, header=None))
1  2  3
4  5  6
7  8  9

EDIT:

编辑:

For convert to excel without index and headers use parameter index=Falseand header=None:

要在没有索引和标题的情况下转换为 excel,请使用参数index=Falseheader=None

New_dataframe.to_excel('test.xlsx', index=False, header=None)