您现在的位置是:网站首页>列表内容
pandas报错AttributeError: DataFrame object has no attribute ix问题_python_
2025-08-26 09:59:43
3572人已围观
简介 pandas报错AttributeError: DataFrame object has no attribute ix问题_python_
pandas报AttributeError: DataFrame object has no attribute ix
在实际操作中有时候需要把采集的数据或者分析完的数据保存为excel中,列名按照执行排序
一开始我采用DataFrame的ix方式去实现是可以达到预期的,不过最近发现好像该方法函数被移除了
运行会抛出以下错误:
Traceback (most recent call last):
File "test.py", line 149, in
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'】
总结
以上为个人经验,希望能给大家一个参考,也希望大家多多支持。
点击排行
- pandas如何获取某个数据的行号_python_
- python进程池Pool中apply方法与apply_async方法的区别_python_
- python array中关于[a,b,c]的使用方式_python_
- Python进程multiprocessing.Process()的使用解读_python_
- selenium常用API的使用过程记录(包括自动登录)_python_
- Python使用multiprocessing如何实现多进程_python_
- pandas报错AttributeError: DataFrame object has no attribute ix问题_python_
- python模拟登陆、POST/GET请求方式_python_
- 解决Windows下PowerShell无法进入Python虚拟环境问题_python_
本栏推荐
-
pandas如何获取某个数据的行号_python_
-
python进程池Pool中apply方法与apply_async方法的区别_python_
-
python array中关于[a,b,c]的使用方式_python_
-
Python进程multiprocessing.Process()的使用解读_python_
-
selenium常用API的使用过程记录(包括自动登录)_python_
-
Python使用multiprocessing如何实现多进程_python_
-
pandas报错AttributeError: DataFrame object has no attribute ix问题_python_
-
python模拟登陆、POST/GET请求方式_python_
-
解决Windows下PowerShell无法进入Python虚拟环境问题_python_

