I have the following pandas dataframe (just an example):
import pandas as pd
df = pd.DataFrame(pd.Series(['a','a','a','b','b','c','c','c','c','b','c','a']), columns = ['Data'])
Data
0 a
1 a
2 a
3 b
4 b
5 c
6 c
7 c
8 c
9 b
10 c
11 a
The goal is to get another column, Stats, that count the element of Data column as following:
Data Stats
0 a
1 a
2 a a3
3 b
4 b b2
5 c
6 c
7 c
8 c c4
9 b b1
10 c c1
11 a a1
Where, for example, a3 means "three consecutive a elements", c4 means "four consecutive c elements" and so on...
Thank you in advance for your help