Categories
Python Answers

How to convert a Python Pandas GroupBy output from Series to DataFrame?

Spread the love

To convert a Python Pandas GroupBy output from Series to DataFrame, we can use count.

For instance, we write

df1.groupby(["Name", "City"])[['Name','City']].count()

to call groupby with count to return the groupby result as a data frame.

Leave a Reply

Your email address will not be published.

If you like the content of this blog, subscribe to my email list to get exclusive articles not available to anyone else.