gpt4 book ai didi

python - 删除 pandas 数据框上的索引和列

转载 作者:太空宇宙 更新时间:2023-11-03 11:16:47 25 4
gpt4 key购买 nike

我有这个列表:

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

输出:

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

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

1  2  3
4 5 6
7 8 9

如何删除那个索引列和行??

最佳答案

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

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

如果需要查看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

编辑:

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

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

关于python - 删除 pandas 数据框上的索引和列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50303300/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com