How can I count a pandas dataframe over duplications
df.groupby(['Name', 'Info1', 'Info2']).size().reset_index().rename(columns={0:"count"})
Given your example df
:
Name Info1 Info2
0 Name1 Name1-Info1 Name1-Info2
1 Name1 Name1-Info1 Name1-Info2
2 Name1 Name1-Info1 Name1-Info2
3 Name2 Name1-Info2 Name1-Info2
4 Name2 Name1-Info2 Name1-Info2
The following:
df.pivot_table(index=list(df), aggfunc='size')
Will return what you're after:
Name Info1 Info2
Name1 Name1-Info1 Name1-Info2 3
Name2 Name1-Info2 Name1-Info2 2