1

I have the following dataframe:

print(df)

Product      Store    Quantity_Sold
   A          NORTH          10
   A          NORTH          5
   A          SOUTH          8

   B          SOUTH          8
   B          SOUTH          5

(...)

I would like to count the number of times the same pair of product and store is present; to illustrate:

print(final_df)

Product      Store       count
   A          NORTH        2
   A          SOUTH        1

   B          SOUTH        2

(...)

I tried with:

df["Product"].value_counts()

But it only works with single columns. How can I create final_df?

Alessandro Ceccarelli
  • 1,775
  • 5
  • 21
  • 41

0 Answers0