Why pandas read_csv issues this warning? (elementwise comparison failed) Why pandas read_csv issues this warning? (elementwise comparison failed) numpy numpy

Why pandas read_csv issues this warning? (elementwise comparison failed)


This is one way to get the same result as with index_col = 0 but without the warning. It may not be the most concise way though:

data = pd.read_csv("Data/led.csv")data.set_index([data.columns.values[0]], inplace=True)data.index.names = [None]

This is a great post on the type of error and, below it, there is a solution for a named column, e.g., index_col=['0'])


I'm not sure exactly why you have an error, though a guess is it could occur if you have numeric and non-numeric data in your index column. Then numpy gets confused when it tries to check whether the index is ordered.

A possible hack:

data = pd.read_csv("Data/led.csv")# assuming first column is named '0'data['0'] = data['0'].astype(int).fillna(0)data = data.set_index('0')


From this discussion, it looks like there is a stray warning in numpy that the developers want to remove: https://github.com/numpy/numpy/issues/6784

My guess (without digging into the pandas source code) is that pandas is first asking whether 0 is a column name (perhaps with 0 in df.columns or something) and then falling back to using 0 as an index when that query returns False.

Hopefully either numpy will remove the warning or pandas will adjust its logic in the future.