Pandas DataFrame如何分组数值列的垃圾箱,然后对其他二进制列进行计数
我有一个数据框:
c1 c2 SED f
1 2 0.2 1
3 3 0.7 1
3 1 0.1 0
8 1 0.6 0
9 2 1 1
4 9 8.3 1
我想将 SED
分组到宽度为 0.5 的 bin 和 foreach bin,计算列 f
为 1 的行数及其行数0.
所以对于这个例子我会得到:
SED_bin cou_0 cou_1
0-0.5 1 1
0.5-1 1 2
8-8.5 0 1
最好的方法是什么? 请注意,这只是 SED 值的一个示例,可能还有更多低于或高于此范围的值,因此我需要通用的分箱。
I have a dataframe:
c1 c2 SED f
1 2 0.2 1
3 3 0.7 1
3 1 0.1 0
8 1 0.6 0
9 2 1 1
4 9 8.3 1
I want to group SED
to bins of width 0.5 and foreach bin, count the number of rows the column f
is 1 and the number of rows it is 0.
So for this example I will get:
SED_bin cou_0 cou_1
0-0.5 1 1
0.5-1 1 2
8-8.5 0 1
What is the best way to do it?
Please note this is just an example of SED values and there could be more below to above this range so I need the binning to be generic.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
一个选项是使用
剪切
+crosstab
:输出:
One option is to use
cut
+crosstab
:Output: