0

I have a DataFrame which has a lot of NAs. pandas's groupby operation is ignoring any combinations with NA in it. Is there a way to include NAs in groups? If not, what are the alternatives to pandas groupby? I really don't want to fill in NAs because the fact that something is missing is useful information.

Edit: I noticed that my question is exactly the same issue reported in groupby columns with NaN (missing) values Has there been any developments technology to get around this issue?

Community
  • 1
  • 1
  • 1
    The question is a bit vague. Could you please show what you tried and what is your desired output? – abudis Aug 07 '15 at 11:48

1 Answers1

1

I will use some kind of non-NA representation for NA only for groupby, which can't be confused with proper data (e.g. -999999 or 'missing')

df.fillna(-999999).groupby(...)

As inplace argument has default value False your original dataframe will not be affected.

zuku
  • 649
  • 8
  • 24