df
['ch*', 'co*', 'DePe*', 'DePe*', 'DePe*', 'pm*', 'tpm*', 'lep*']
['ch*', 'co*', 'DePe*', 'DePe*', 'DePe*', 'am*', 'te*', 'qe*','te*']
['ch*', 'co*', 'DePe*', 'ch*', 'DePe*', 'DePe*', 'tpm*', 'lep*']
['ch*', 'DePe*', 'eeae*', 'ps*', 'er*']
Name: df, Length: 4, dtype: object
我需要计算在“DePe*”的最后一个实例(从左到右)之后发生的项 我期待这样的结果。你知道吗
df count
['ch*', 'co*', 'DePe*', 'DePe*', 'DePe*', 'pm*', 'tpm*', 'lep*'] 3
['ch*', 'co*', 'DePe*', 'DePe*', 'DePe*', 'am*', 'te*', 'qe*','te*'] 4
['ch*', 'co*', 'DePe*', 'ch*', 'DePe*', 'DePe*', 'tpm*', 'lep*'] 2
['ch*', 'DePe*', 'eeae*', 'ps*', 'er*'] 3
将
list.index
与reversed
一起使用:我是python新手,所以这个解决方案可能不是您想要的。但我认为这是可行的:
将
apply
与lambda函数和index
的反向lists
一起使用,效果很好,因为在python中列表是基于0的索引:如果可能,某些值不存在,请在
try-except
语句中指定值:相关问题 更多 >
编程相关推荐