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

Dia*_*rts 74 python dataframe pandas

当我尝试使用 Pandas 数据框的 .ix 属性拉出一列时出现此错误,例如df.ix[:, 'col_header']

AttributeError: 'DataFrame' object has no attribute 'ix'
Run Code Online (Sandbox Code Playgroud)

该脚本今天早上工作,但今天下午我在新安装的 Pandas 的新 Linux 环境中运行它。有没有其他人见过这个错误?我在这里和其他地方搜索过,但找不到。

Dr_*_*ope 76

尝试 df.iloc[:, integer]

.ix 已弃用

顺便说一句,df.loc[:,'col_header']用于 str 或布尔索引

  • *“`.ix` 已弃用”* - `.ix` 已被删除,而不是弃用(这意味着不鼓励但仍然可用)。 (3认同)

Abi*_*med 27

将 .ix 更改为 .loc,它应该可以正常工作。


ALo*_*llz 26

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

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


小智 5

尝试以下步骤:1)安装新版本的 Pandas 2)使用 .loc 而不是 .ix