Python 属性错误:';数据帧';对象没有属性';ix和x27;

Python 属性错误:';数据帧';对象没有属性';ix和x27;,python,pandas,dataframe,Python,Pandas,Dataframe,当我尝试使用pandas数据帧的.ix属性拉出一列时,例如,df.ix[:,'col_header'],会出现此错误 AttributeError: 'DataFrame' object has no attribute 'ix' 这个脚本今天早上运行正常,但今天下午我在一个新的Linux环境中运行了它,并安装了新的Pandas。以前有谁见过这个错误吗?我在这里和其他地方都搜索过,但找不到它。今天(2020年1月30日)重新安装将安装pd.\uuuu版本\uuuu==“1.0.0”。随之而来的

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

AttributeError: 'DataFrame' object has no attribute 'ix'
这个脚本今天早上运行正常,但今天下午我在一个新的Linux环境中运行了它,并安装了新的Pandas。以前有谁见过这个错误吗?我在这里和其他地方都搜索过,但找不到它。

今天(2020年1月30日)重新安装将安装
pd.\uuuu版本\uuuu==“1.0.0”
。随之而来的是一场灾难

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


熊猫1.0.0也有同样的问题,这对我来说很有效

以管理员身份打开Anaconda提示符(cmd),然后

康达=0.25.1

您的新版本将被旧版本覆盖

谢谢

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

一列:

df[['sepal width']]
两列:

df[['sepal width','petal width']]
特殊列(选择列包括“长度”):


尝试
df.iloc[:,integer]

.ix
已弃用


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

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

我使用了.loc()而不是.ix(),它可以工作。

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

我正在阅读Wes McKinney的《Python用于数据分析》一书,在使用索引检索行时遇到了与Dataframe.ix[]相同的问题。
我用iloc替换ix,它工作得很好。

我使用.ix,因为我混合了索引、标签和整数。loc()不能像.iloc那样解决问题;两者都以错误告终。我有意使用.ix,因为当索引是整数和标签的混合时,它是一条快车道

例如,df类似于:

我的解决方法是备份列和索引,用整数替换,使用.iat,然后恢复df,就像它开始时一样。我有点像:

# Save the df and replace indec and columns with integers
lista_colonne = list(df.columns)  
df.columns = range(0,len(lista_colonne))    
nome_indice = df.index.name
lista_indice = list(df.index)
df['Indice'] = range(0,len(lista_indice))
df.index = df['Indice']
del df['Indice']

  ... indexing here with .iat in place of .ix


# Now back as it was
df.columns = lista_colonne
df['Indice'] = lista_indice
df.index = df['Indice']
del df['Indice']
df.index.name = nome_indice
再见,法比奥

  • 男人们试图更新当前的熊猫
  • 将.ix替换为.iloc 更换后,它对我很好 有关详细信息,请参阅文档
  • 我必须这样做:

    returns.ix['2015-01-01':'2015-12-31'].std()
    
    经过许多努力,我用以下方法实现了这一点:

    returns.xs(key='2015',axis=0).std()
    

    我相信至少在这种情况下,我们可以使用横截面和过滤器,使用2015作为键。

    是的,没错。将
    df.ix[]
    替换为
    df.iloc[]
    df.loc[]

    它对我有效


    使用ix[]的df.loc[]instade

    您运行的是旧版本的pandas。看到这个了吗?我收到“基于位置的索引只能有[integer,integer slice(包括起点,不包括终点),整数列表,布尔数组]类型。”顺便说一句,df.loc[:,'col_header']用于str索引”,如果索引器是布尔掩码,则需要它。
    returns.xs(key='2015',axis=0).std()