Skip to content
Advertisement

TypeError: ‘<' not supported between instances of 'numpy.ndarray' and 'int' with a csv file

I am trying to find specific elements (those with a value less than 5) in a particular data column from an imported csv file. However I keep encountering this strange error. The code reads as follows:

JavaScript

Advertisement

Answer

Apparently you are doing:

JavaScript

I’m a little surprised that it isn’t complaining about instances of string (or string dtype) and int.

With loadtxt the default dtype is float, and it raises an error if some strings can’t be parsed as floats. np.genfromtxt assigns those values nan instead.

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement