Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I am getting this error when I try to use the .ix attribute of a pandas data frame to pull out a column, e.g. df.ix[:, 'col_header'].

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

The script worked 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.

like image 324
Diarmid Roberts Avatar asked Jan 30 '20 17:01

Diarmid Roberts


People also ask

What is Loc and ILOC?

loc[] is used to select rows and columns by Names/Labels. iloc[] is used to select rows and columns by Integer Index/Position. zero based index position.

How do you convert a data frame to a series?

To convert the last or specific column of the Pandas dataframe to series, use the integer-location-based index in the df. iloc[:,0] . For example, we want to convert the third or last column of the given data from Pandas dataframe to series.


2 Answers

try df.iloc[:, integer]

.ix is deprecated

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

like image 159
Dr_Hope Avatar answered Oct 13 '22 05:10

Dr_Hope


Change .ix to .loc and it should work correctly.

like image 24
Abidi Mohamed Avatar answered Oct 13 '22 05:10

Abidi Mohamed