首页 > 解决方案 > 传递参数时重命名轴错误的 Pandas 错误

问题描述

我有一个 Dataframe,它返回一个时间范围内完成的销售计数,该时间范围存储到一个变量中total_sale_count

total_sale_count_old = pd.DataFrame(total_sale_count, columns=['TotalSaleCount'])
total_stop_count = total_sale_count_old.set_index('TotalSaleCount').T.rename_axis('Total Sales').rename_axis(None, 1).reset_index()

以上抛出错误

TypeError: rename_axis() takes from 1 to 2 positional arguments but 3 were given

标签: pandas

解决方案


我相信你需要:

total_sale_count = pd.Series([1,2,3], index=list('abc'))

total_stop_count = pd.DataFrame([total_sale_count], index=['TotalSaleCount'])
print (total_stop_count)
                a  b  c
TotalSaleCount  1  2  3

推荐阅读