In pandas, I want to group by two columns and then do a count. After that I want to drop on of the columns I grouped on and calculate the average for the counts. I know how to do this in sql easily, but run into issues in Pandas. I can't drop one of the columns I grouped on previously. Do anyone know how to do this nicely?
(Just care about the end result, the procedure doesn't have to be this way if there is a better one)
Eg:
Name, City
Anna, New York
Carl, New York
Carl, New York
Steven, London
Carl, London
Anna, Paris
Carl, Paris
Carl, Paris
Group by 'Name' and 'City', then count:
Name, City, Count
Anna, New York, 1
Carl, New York, 2
Steven, London, 1
Carl, London, 1
Anna, Paris, 1
Carl, Paris, 2
Drop 'City' and take the average count for each 'Name':
Name, Count
Anna, 1
Carl, 1.66667
Steven, 1