Starting with a dataframe like this:
df = pd.DataFrame({"Cat1":['a','a', 'b','b','c','c','c', 'c', 'c'], "Cat2":[1,1,1,2,1,1,2,2,2]})
df
Out[2]:
Cat1 Cat2
0 a 1
1 a 1
2 b 1
3 b 2
4 c 1
5 c 1
6 c 2
7 c 2
8 c 2
How can I manipulate the data in order to produce a count of each "Cat1"-"Cat2" pair, in increasing order? The result would look like this:
df = pd.DataFrame({"Cat1":['a','a', 'b','b','c','c','c', 'c', 'c'], "Cat2":[1,1,1,2,1,1,2,2,2], "Count":[1,2,1,1,1,2,1,2,3]})
df
Out[4]:
Cat1 Cat2 Count
0 a 1 1
1 a 1 2
2 b 1 1
3 b 2 1
4 c 1 1
5 c 1 2
6 c 2 1
7 c 2 2
8 c 2 3