pandas - 传递参数时重命名轴错误的 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
解决方案
我相信你需要:
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
推荐阅读
- c - 如果我在 C 中的 for 循环中声明一个变量,它会被创建多次吗?
- github - 如何使用新的 github cli 向远程仓库发出拉取请求,而无需推送远程分支?
- php - 根据从下拉列表中选择的值更改打印的单词
- amazon-web-services - AWS WAF 在尝试上传图像时出现 403 禁止错误
- c++ - 如何将整数错误代码转换为人类可读的字符串?
- github - 如何以编程方式下载 GitHub 存储库默认分支的 ZIP 文件?
- c++ - C++ 外部库问题
- c# - 提交第一个表单后如何导航到 Razor 页面中的下一个选项卡
- javascript - 为什么我不能在 App Component 中使用 MyContext?
- java - 运行 javafx 程序时启动错误