[Solved] AttributeError: ‘DataFrame’ object has no attribute ‘ix’

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.

Solution #1:

try df.iloc[:, integer]

.ix is deprecated

By the way, df.loc[:,'col_header'] is for str or Boolean indexing

Respondent: Dr_Hope

Solution #2:

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

Removed Series.ix and DataFrame.ix (GH26438)

Respondent: ALollz

Solution #3:

Change ix by .loc it will work corrcetly.

Respondent: Abidi Mohamed

Solution #4:

Try following steps:
1) installing new version of Pandas
2) use .loc instead of .ix

Respondent: Saugat Bashyal

Solution #5:

had same issue with pandas 1.0.0, this worked for me

Open Anaconda Prompt (cmd) as Administrator, then

conda install pandas==0.25.1

Your newer pandas version will be overwritten by older one!

Respondent: Eric Stralsund

Solution #6:

it works for me

Use df.loc[] instade of ix[]

Respondent: Dhiren Biren

Solution #7:


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

Respondent: Diarmid Roberts

Solution #8:

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]]
Respondent: HelloNewWorld

Solution #9:

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

Respondent: user3752821

Solution #10:

I am reading the book ‘Python for data analysis’ by Wes McKinney and I met the same problem of Dataframe.ix[] while retrieving the rows with index.
I replace ix by iloc and it works perfectly.

Respondent: Avicii

Solution #11:

I’m using .ix as I have mixed indexing, labels and integers. .loc() does not solve the issue as well as .iloc; both are ending in errors. I was intentionally using .ix because it was the fast lane when the index is a mix of integers and labels.

As example a df like:

enter image description here

My way out is to back-up columns and index, replace with integers, use .iat and then restore the df as it was at the beginning. I have something like:

# Save the df and replace indec and columns with integers
lista_colonne = list(df.columns)  
df.columns = range(0,len(lista_colonne))    
nome_indice =
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'] = nome_indice

Bye, Fabio.

Respondent: Fabio Pomi

Solution #12:

I had to do this:


After much ado I made it happen using this:


I believe at least for this case we can use cross section and filter using 2015 as key.

Respondent: user13989469

Solution #13:

Yes, that’s right. Replace df.ix[] by df.iloc[] or df.loc[]

Respondent: Pravu Chaudhary

Solution #14:

  1. Guys try to update current pandas
  2. replace .ix with .iloc
    after replacing its works well for me
    For details refers documentations
Respondent: SIVA001

The answers/resolutions are collected from stackoverflow, are licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0 .

Most Popular

To Top
India and Pakistan’s steroid-soaked rhetoric over Kashmir will come back to haunt them both clenbuterol australia bossier man pleads guilty for leadership role in anabolic steriod distribution conspiracy