已解决:pandas报AttributeError: DataFrame object has no attribute ix错误

1. 问题描述

python使用pandas DataFrame.ix的时候 AttributeError: ‘DataFrame’ object has no attribute ‘ix’。
已解决:pandas报AttributeError: DataFrame object has no attribute ix错误_第1张图片

2. 问题原因

在使用进行DataFrame.ix进行表中的数据块选择的时候,会抛出’DataFrame’ object has no attribute ‘ix’,这个是由于在不同的pandas的版本中,DataFrame的相关属性已过期,已不推荐使用导致的。

3. 解决方案

可以使用loc进行替换。

full.ix[(full.TPP==4)&(full.Sex=='female')&(full.Pclass==3),'TPP']=2

替换为

full.loc[(full.TPP==4)&(full.Sex=='female')&(full.Pclass==3),'TPP']=2

你可能感兴趣的:(#,python常见问题,pandas)