pandas AttributeError: 'DataFrame' 对象没有属性 'ix'

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/59991397/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 06:25:13  来源:igfitidea点击:

AttributeError: 'DataFrame' object has no attribute 'ix'

pythonpandasdataframe

提问by Diarmid Roberts

I am getting the above error when I try to use the .ix attribute of a pandas dataframe to pull out a column, e.g. df.ix[:, 'col_header']. The script worked as of this morning, but this afternoon I ran it in a new linux environment with a fresh install of Pandas. Has anybody else seen this error before? I've searched here and elsewhere but can't find it.

当我尝试使用 Pandas 数据框的 .ix 属性拉出一列时出现上述错误,例如 df.ix[:, 'col_header']。该脚本从今天早上开始运行,但今天下午我在一个全新的 Pandas 安装的新 Linux 环境中运行它。有没有其他人见过这个错误?我在这里和其他地方搜索过,但找不到。

回答by ALollz

A fresh install today (Jan 30, 2020) would install pd.__version__ == '1.0.0'. With that comes a removal of many deprecated features.

今天(2020 年 1 月 30 日)全新安装将安装pd.__version__ == '1.0.0'. 随之而来的是删除了许多已弃用的功能

Removed Series.ix and DataFrame.ix (GH26438)

删除了 Series.ix 和 DataFrame.ix(GH26438)

回答by Dr_Hope

try df.iloc[:, 'col_header']

尝试 df.iloc[:, 'col_header']

.ixis deprecated

.ix已弃用

回答by Abidi Mohamed

Change ix by .loc it will work corrcetly.

通过 .loc 更改 ix 它将正常工作。

回答by Eric Stralsund

had same issue with pandas 1.0.0, this worked for me

pandas 1.0.0 有同样的问题,这对我有用

Open Anaconda Prompt (cmd) as Administrator, then

以管理员身份打开 Anaconda Prompt (cmd),然后

conda install pandas==0.25.1

畅达安装Pandas==0.25.1

Your newer pandas version will be overwritten by older one!

您较新的Pandas版本将被旧版本覆盖!

回答by Diarmid Roberts

Thanks.

谢谢。

In retrospect I probably didn't need to use .ix, as df['col_header'] works for me, and is neater.

回想起来,我可能不需要使用 .ix,因为 df['col_header'] 对我有用,而且更整洁。

回答by HelloNewWorld

one column:

一栏:

df[['sepal width']]

two columns:

两列:

df[['sepal width','petal width']]

special columns(select column include 'length'):

特殊列(选择列包括“长度”):

df[[c for c in df.columns if 'length' in c]]

回答by user3752821

I used .loc() instead of .ix() and it worked.

我使用 .loc() 而不是 .ix() 并且它起作用了。