计算数据帧尾部的值的顺序 [英] Counting the sequence of a value in the tail of a dataframe
本文介绍了计算数据帧尾部的值的顺序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图在熊猫数据框的尾巴中获得1秒的计数.从此数据框中:
I am trying to get the count of 1s at the tail of a pandas dataframe. From this dataframe:
x
1
2
3
1
1
1
我想获得 3 的计数.如果尾部没有1,则该函数应返回0.我找不到任何熊猫函数来执行此操作.有什么想法吗?
I want to get the count of 3. If there are no 1s in the tail, then the function should return 0. I could not find any function of pandas to do this. Any ideas?
推荐答案
让我们使用它:
d1.x[::-1].eq(1).cumprod().sum()
这篇关于计算数据帧尾部的值的顺序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文