Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
4.3k views
in Technique[技术] by (71.8m points)

pandas数据新增一列计算连续次数

求教大神,想要计算一下一列中每一个数字连续出现的次数,请问有什么简单的方法吗?因为原始数据非常大,所以希望性能好一点,谢谢~

df1 = pd.DataFrame({'X': [1, 2, 2, 1, 1, 1, 2, 1, 1, 1]})
df1

希望生成以下的结果
image


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神解答

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...