Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

groupbycolumn

# import pandas
import pandas as pd
  
# create dataframe
df = pd.DataFrame({'Name': ['Mukul', 'Rohan', 'Mukul', 'Manoj',
                            'Kamal', 'Rohan', 'Robin'],
                     
                   'age': [22, 22, 21, 20, 21, 24, 20]})
  
# print dataframe
print(df)
  
# use count() and sort()
df = df.groupby(['Name'])['age'].count().reset_index(
  name='Count').sort_values(['Count'], ascending=False)
  
# print dataframe
print(df)
Source by www.geeksforgeeks.org #
 
PREVIOUS NEXT
Tagged: #groupbycolumn
ADD COMMENT
Topic
Name
7+4 =