pandas报错AttributeError: DataFrame object has no attribute ix问题

2024-03-01 0 877
目录
  • pandas报AttributeError: DataFrame object has no attribute ix
  • 根本原因
  • 解决方式
  • 总结

pandas报AttributeError: DataFrame object has no attribute ix

在实际操作中有时候需要把采集的数据或者分析完的数据保存为excel中,列名按照执行排序

一开始我采用DataFrame的ix方式去实现是可以达到预期的,不过最近发现好像该方法函数被移除了

运行会抛出以下错误:

Traceback (most recent call last): File "test.py", line 149, in <module> test() File "test.py", line 143, in test result_data, cols = add_excel(sheet_list, cols, excels, self.path) File "test.py", line 47, in add_excel DataFrame = DataFrame.ix[:, cols] File "E:\\project\\test\\venv\\lib\\site-packages\\pandas\\core\\generic.py", line 5273, in __getattr__ return object.__getattribute__(self, name)AttributeError: 'DataFrame' object has no attribute 'ix'

根本原因

由于安装了较高版本的pandas,官方移除了一些不推荐使用的方法函数,详情请参考:

点击查看官方删除了不推荐使用的功能

解决方式

根据官方说明,ix已被移除,可用.iloc替代:

# DataFrame.ix[:, cols] # 已移除,不推荐使用
DataFrame.iloc[:, cols] # 列按指定下标排序 cols=【0,2,1】
DataFrame.loc[:, col_header] # 列按指定下标排序 cols=【\’col\’,\’col1\’】

总结

以上为个人经验,希望能给大家一个参考,也希望大家多多支持悠久资源网。

您可能感兴趣的文章:

  • pandasdataframe统计填充空值方式
  • Python数据分析:pandas中Dataframe的groupby与索引用法
  • PandasDataFrame分组求和、分组乘积的实例
  • pandasDataFrame.to_sql()用法小结
  • pandas如何实现两个dataframe相减
  • Pandas实现复制dataframe中的每一行

收藏 (0) 打赏

感谢您的支持,我会继续努力的!

打开微信/支付宝扫一扫,即可进行扫码打赏哦,分享从这里开始,精彩与您同在
点赞 (0)

悠久资源 Python pandas报错AttributeError: DataFrame object has no attribute ix问题 https://www.u-9.cn/jiaoben/python/179883.html

常见问题

相关文章

发表评论
暂无评论
官方客服团队

为您解决烦忧 - 24小时在线 专业服务