How to resolve the error: dataframe object has no attribute ix?

490    Asked by DavidEdmunds in Data Science , Asked on Feb 14, 2023

 I was learning a Classification-based collaboration system and while running the code I faced the error AttributeError: 'DataFrame' object has no attribute 'ix'. Here is the code I have written until now. X=bank_full.ix[:,(18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36)].values
Answered by Clare Matthews

To resolve the error: dataframe object has no attribute ix:


Just use .iloc instead (for positional indexing) or .loc (if using the values of the index). To read more about loc/ilic/iax/iat, please visit this question on Stack Overflow. To quote the top answer there: loc: only work on index iloc: work on position ix: You can get data from dataframe without it being in the index at: get scalar values. It's a very fast loc iat: Get scalar values. It's a very fast iloc http://pyciencia.blogspot.com/2015/05/obtener-y-filtrar-datos-de-un-dataframe.html Note: As of pandas 0.20.0, the .ix indexer is deprecated in favour of the more stric .iloc and .loc indexers.



Your Answer

Answer (1)

Hey! The error you're getting is because `.ix[]` was deprecated in **pandas** a while back and is no longer available in newer versions. That’s why you’re seeing the `'DataFrame' object has no attribute 'ix'` error.

ragdoll hit

You can fix it by using `.iloc[]` instead, which is meant for **positional indexing** (and looks like what you're doing here). Try replacing your line with: 

```python

X = bank_full.iloc[:, [18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36]].values

```

This should work without any errors assuming `bank_full` is a valid DataFrame and the column indices exist. Let me know if you're still stuck!


1 Month

Interviews

Parent Categories