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.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *