按列(“租户”)分组并获取(“值”)列中最大连续 1
我有一个如下所示的 df:
租户 | 价值 |
---|---|
x | 1 |
x | 1 |
x | 0 |
x | 1 |
y | 1 |
y | 0 |
结果: 租户 X 应为 2,租户 y 应为 1
我正在尝试获取每组的最大连续值 1。如果值 1 之间有任何 0,则计数重新开始。 我是 python 新手,不知道从哪里开始。谢谢
I have a df shown below:
Tenant | Value |
---|---|
x | 1 |
x | 1 |
x | 0 |
x | 1 |
y | 1 |
y | 0 |
Results:
Tenant X should be 2 and tenant y should be 1
I am trying to get the max consecutive value 1s per group. If there are any 0 in between the value 1 the count starts over.
I am new to python and not sure where to start. Thank you
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以尝试:
如果
Value
列可以有0
或1
以外的其他值,您应该使用:You could try:
If the
Value
column can have other values than0
or1
you should rather use: