PeterYoung
PeterYoung

Reputation: 21

scipy.stats.mode has 'TypeError :unorderable types str() > float()'

the code is

import scipy.stats as stats
stats.mode(df['Gender']')

three are some null in df['Gender'],and the problem is 'TypeError: unorderable types: str() > float()'.[scipy(0.19.1) python3.5.2] How? please,THx.

Upvotes: 1

Views: 376

Answers (1)

Clock Slave
Clock Slave

Reputation: 7957

As you said the error arises because there are missing values in your data. I am assuming you are using pandas dataframe. To take the mode, you can omit the rows which have missing values.

stats.mode(df.loc[~(df['G'].isnull()),'G'])

Upvotes: 2

Related Questions