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
Remove Index and columns on pandas dataframe
提问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 DataFrame
it 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=False
and header=None
:
要在没有索引和标题的情况下转换为 excel,请使用参数index=False
和header=None
:
New_dataframe.to_excel('test.xlsx', index=False, header=None)