重命名未命名的列Pandas数据框 [英] Rename unnamed column pandas dataframe
本文介绍了重命名未命名的列Pandas数据框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的csv文件的第一列没有列名,我想对其重命名.通常,我会执行data.rename(columns={'oldname':'newname'}, inplace=True)
,但是csv文件中没有名称,只有''.
My csv file has no column name for the first column, and I want to rename it. Usually, I would do data.rename(columns={'oldname':'newname'}, inplace=True)
, but there is no name in the csv file, just ''.
推荐答案
您可以使用来查看当前数据框
data.head()
You can view the current dataframe using
data.head()
如果返回'Unnamed: 0'
作为列标题,则可以通过以下方式对其进行重命名:
if that returns 'Unnamed: 0'
as the column title, you can rename it in the following way:
data.rename( columns={'Unnamed: 0':'new column name'}, inplace=True )
这篇关于重命名未命名的列Pandas数据框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文