I have a data frame like this Main DataFrame . How Can I extract new data frame from it like: Second DataFrame
I know df['Group'].value_counts().index
shows me counts of each 'Group' but I don't know how to create new dataframe with it.
You get a new dataframe by using for example groupby
like this to do this counting:
df.groupby("Group", as_index=False).size()
Other interesting options for groupby that you might want to use depending on use case are dropna=False
and sort=False
.
And to rename the size column to counts you use can use rename: .rename(columns={'size': 'Count'})
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.