pandas -删除列名 [英] Pandas - delete column name
本文介绍了 pandas -删除列名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我只想删除列名(x,y,z) 仅使用数据
I want to delete to just column name (x,y,z) use only data
In [68]: df
Out[68]:
x y z
0 1 0 1
1 2 0 0
2 2 1 1
3 2 0 1
4 2 1 0
我希望将结果打印为以下内容.
i want to print result to same as below.
Out[68]:
0 1 0 1
1 2 0 0
2 2 1 1
3 2 0 1
4 2 1 0
有可能吗? 我该怎么做?
is it possible? how i can do this?
推荐答案
在熊猫中,默认情况下需要列名称.
In pandas by default need column names.
但是如果真的想要'remove'
列,则强烈建议不要这样做,因为可能会获得重复的列名,请分配空字符串:
But if really want 'remove'
columns what is strongly not recommended, because get duplicated column names is possible assign empty strings:
df.columns = [''] * len(df.columns)
但是如果需要将df
写入不带列的文件,并为索引添加参数header=False
和index=False
到 to_excel
.
But if need write df
to file without columns and index add parameter header=False
and index=False
to to_csv
or to_excel
.
df.to_csv('file.csv', header=False, index=False)
df.to_excel('file.xlsx', header=False, index=False)
这篇关于 pandas -删除列名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文