AttributeError: 'DataFrame' object has no attribute 'ix'
Python error · pandas 1.0 and later
The notebook was written for an older pandas. .ix was removed in pandas 1.0 (January 2020), so every line that uses it stops with this error. A Series gives the same error: 'Series' object has no attribute 'ix'.
Why it happens
.ix mixed two ways of selecting rows: by label, and by position when the index wasn’t made of integers. pandas split them into .loc (labels) and .iloc (positions), deprecated .ix in version 0.20 and removed it in 1.0. Course and tutorial notebooks written before 2020 still use it.
How to fix it
Most .ix lines select by row and column labels; for them, write .loc:
Before
df = pd.read_csv("sales.csv")
city = df.ix[0, "city"]
After
df = pd.read_csv("sales.csv")
city = df.loc[0, "city"]
If the index isn’t made of integers and the line selects by position (df.ix[:5] on a table indexed by dates, say), write .iloc instead: df.iloc[:5].
In NoteRun
NoteRun checks a notebook before you run it. The cell with .ix is marked “This cell may not run”, and the fix is right there: tap Fix, or Fix all for the whole notebook. Nothing changes until you tap, you see every change first, and Undo brings the notebook back. When a line might select by position, NoteRun tells you to check it.
On your iPhone or iPad, download a sample notebook that has this error and open it in NoteRun.