Following is the df
from io import StringIO
import pandas as pd
df = pd.read_csv(StringIO("""
Group Date Rank
A 01-01-2023 1
A 01-02-2023 2
A 01-03-2023 3
A 01-04-2023 2
A 01-05-2023 1
A 01-06-2023 1
A 01-07-2023 3
A 01-08-2023 2
B 01-01-2023 2
B 01-02-2023 3
B 01-03-2023 2
B 01-04-2023 1
B 01-05-2023 3
B 01-06-2023 2
B 01-07-2023 1
B 01-08-2023 3"""), sep="\s+")
It has two groups date and rank achieved on each day.
I want following output :
Group Count of 1 Count of 2 Count of 3
A 3 3 2
B 2 3 3
First I counted each Rank using for loop and if loop with value_count() for each Rank and stored in list. later on converted list into df
I tried using groupby,agg value_count() of each rank and then created df.
I want to know how to solve this with pivot as there are various categories on which ranking is done and each category rank total is required.