本文介绍了 pandas :在df中重命名轴的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个如下所示的df:
I have a df which looks like this:
Column 1
Channel
Apples 1.0
Oranges 2.0
Puppies 3.0
Ducks 4.0
我想重命名轴,使它看起来像这样:
I would like to rename the axis so it looks like this:
Channel Column 1
Apples 1.0
Oranges 2.0
Puppies 3.0
Ducks 4.0
我尝试了这些,但得到了相同的错误味精:
I tried these but got the same error msg:
merged_df.rename_axis("Channel")
merged_df.rename_axis("Channel", axis='columns')
TypeError: 'str' object is not callable
推荐答案
这是一种黑客技巧,可让您获得最终想要的外观。
This is kind of a hack to get you what you eventually wanted it to look like.
df = pd.read_csv(data, sep='\s{2,}', index_col='Channel', engine='python')
df
df_excel_format = df.rename_axis('Channel', axis=1)
del(df_excel_format.index.name)
df_excel_format
这篇关于 pandas :在df中重命名轴的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!