我有一个数据帧(df
),在其中我使用以下命令重命名其中一列:
print('Type Before',type(df))
df= df.rename(columns={df.columns[14]: "Total requests" }, inplace = True)
print('Type after',type(df))
如果我在列名更改前后检查type
,数据帧将从DataFrame
更改为NoneType
Type Before <class 'pandas.core.frame.DataFrame'>
Type after<class 'NoneType'>
是否有一种方法可以使用列号更改列的名称,同时将类型保留为数据帧
如果使用
inplace=True
,则返回None
因此需要删除
inplace=True
并重新分配:或者可以删除
inplace
,但我认为inplace
不是好的做法,请检查this和this:耶斯雷尔解释了你接收
None
背后的问题,所以我没有什么要补充的。我将提供非常类似的方法,只是使用较少的带有list
的字母,而不是columns
:相关问题 更多 >
编程相关推荐