Skip to content Skip to sidebar Skip to footer

How To Filter And Group Pandas DataFrame To Get Count For Combination Of Two Columns

I am sorry I could not fit the whole problem in the Title in a concise way. Pardon my English. I will explain my problem with an example. Say I have this dataset: dff = pd.DataFram

Solution 1:

x = dff.groupby(["Name", "slot"]).ID.nunique().reset_index(name="count")
print(x)

Prints:

  Name slot  count
0    1    2      2
1    1    4      2
2    2    4      2
3    3    4      2
4    5    4      2

Post a Comment for "How To Filter And Group Pandas DataFrame To Get Count For Combination Of Two Columns"