1

Given the following sample dataframe:

df = 

Car       Country  

BMW       Germany
Tesla     USA
BMW       Germany
Mercedes  France
Tesla     USA

Based on unique values of column Country I want to get count and naming of column Car. Desired output:

Germany: 
BMW - 2

USA:
Telsa - 2

France:
Mercedes - 1

I have tried to play with pivot table but it was mess

Mamed
  • 1,102
  • 8
  • 23

1 Answers1

1

A classic use for groupby:

df.groupby(["Country", "Car"]).size()
Code Different
  • 90,614
  • 16
  • 144
  • 163