Create new columns from aggregated categories
Clash Royale CLAN TAG #URR8PPP Create new columns from aggregated categories I have a dataframe looks like: SK_ID_CURR CREDIT_ACTIVE 0 215354 Closed 1 215354 Active 2 215354 Active 3 215354 Active 4 215354 Active 5 215354 Active 6 215354 Active 7 162297 Closed 8 162297 Closed 9 162297 Active I would like to aggregate the number of active and closed credits for each id, and then make a new column for Active_credits , Closed_credits with the number of corresponding active and closed credits for each id. Active_credits Closed_credits What is your expected output? – Akshay Nevrekar 10 mins ago 2 Answers 2 You can use pandas.crosstab , which avoids your suggested intermediary step: pandas.crosstab res = pd.crosstab(df['...