大 pandas groupby忽略新手 [英] pandas groupby ignoring NAs

查看:150
本文介绍了大 pandas groupby忽略新手的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个DataFrame,它有很多的NAs。熊猫的groupby操作忽略了NA中的任何组合。有没有办法将新生分为几组?如果不是,pandas groupby有什么选择?我真的不想填写新闻部,因为缺少的东西是有用的信息。

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.

编辑:我注意到我的问题与报道中的问题完全相同具有NaN(缺少)值的groupby列
是否有任何开发技术来解决这个问题?

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?

推荐答案

我会为NA使用某种非NA表示,不能与正确的数据混淆(例如-999999或'missing')

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(...)

inplace 参数具有默认值 False 您的原始数据框不会受到影响。

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

这篇关于大 pandas groupby忽略新手的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆