Count most frequent group with Nan values
Count most frequent group with Nan values basically I would like to count number of the most frequent item grouped by 2 variables. I use this code: dfgrouped = data[COLUMNS.copy()].groupby(['Var1','Var2']).agg(lambda x: stats.mode(x)[1]) This code works, but does not work on columns that have Nan values, since NaN values are float and others are str. So this error is shown: '<' not supported between instances of 'float' and 'str' I would like to omit NaN values and count mode for the rest. So str(x) is not a solution. And scipy.stats.mode(x, nan_policy='omit') does not work neither with an error: TypeError: ufunc 'isfinite' not supported for the input types, and the inputs could not be safely coerced to any supported types according to the casting rule ''safe'' Could you please give me an advice how to deal with that. Thanks 3 Answers 3 ...