pandas:在df中重命名轴

时间:2016-09-15 09:48:49

标签: python pandas dataframe

我的df看起来像这样:

                Column 1
Channel          
Apples            1.0
Oranges           2.0
Puppies           3.0
Ducks             4.0

我想重命名轴,看起来像这样:

Channel         Column 1          
Apples            1.0
Oranges           2.0
Puppies           3.0
Ducks             4.0

我尝试了这些但得到了同样的错误信息:

merged_df.rename_axis("Channel")
merged_df.rename_axis("Channel", axis='columns')

TypeError: 'str' object is not callable

1 个答案:

答案 0 :(得分:1)

这是一种让你最终想要它的样子。

df = pd.read_csv(data, sep='\s{2,}', index_col='Channel', engine='python')
df

Image

df_excel_format = df.rename_axis('Channel', axis=1)
del(df_excel_format.index.name)
df_excel_format

Image