pandas groupby删除列

编程入门 行业动态 更新时间:2024-10-27 06:33:21
本文介绍了 pandas groupby删除列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在按操作进行简单分组,试图比较分组均值.如下所示,我从一个较大的数据框中选择了特定的列,从中删除了所有缺失的值.

I'm doing a simple group by operation, trying to compare group means. As you can see below, I have selected specific columns from a larger dataframe, from which all missing values have been removed.

但是当我分组时,我丢失了几列:

But when I group by, I am losing a couple of columns:

我从来没有遇到过熊猫,而且在堆栈溢出中我找不到其他类似的东西.有人有见识吗?

I have never encountered this with pandas, and I'm not finding anything else on stack overflow that is all that similar. Does anybody have any insight?

推荐答案

我认为它是Automatic exclusion of 'nuisance' columns,它描述了此处.

I think it is Automatic exclusion of 'nuisance' columns, what described here.

示例:

df = pd.DataFrame({'C': {0: -0.91985400000000006, 1: -0.042379, 2: 1.2476419999999999, 3: -0.00992, 4: 0.290213, 5: 0.49576700000000001, 6: 0.36294899999999997, 7: 1.548106}, 'A': {0: 'foo', 1: 'bar', 2: 'foo', 3: 'bar', 4: 'foo', 5: 'bar', 6: 'foo', 7: 'foo'}, 'B': {0: 'one', 1: 'one', 2: 'two', 3: 'three', 4: 'two', 5: 'two', 6: 'one', 7: 'three'}, 'D': {0: -1.131345, 1: -0.089328999999999992, 2: 0.33786300000000002, 3: -0.94586700000000001, 4: -0.93213199999999996, 5: 1.9560299999999999, 6: 0.017587000000000002, 7: -0.016691999999999999}})

print (df) A B C D 0 foo one -0.919854 -1.131345 1 bar one -0.042379 -0.089329 2 foo two 1.247642 0.337863 3 bar three -0.009920 -0.945867 4 foo two 0.290213 -0.932132 5 bar two 0.495767 1.956030 6 foo one 0.362949 0.017587 7 foo three 1.548106 -0.016692 print( df.groupby('A').mean()) C D A bar 0.147823 0.306945 foo 0.505811 -0.344944

我认为您可以检查 DataFrame.dtypes

I think you can check DataFrame.dtypes.

更多推荐

pandas groupby删除列

本文发布于:2023-10-17 03:00:46,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1499581.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:pandas   groupby

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!