alex_bn_lee

导航

【863】Calculate records based on the same value

Suppose we have a dataframe, it has a column of "country". It lists different names of country's names, and for one country maybe it has multiple records. Our task is to create a new dataframe which include the country's names and their corresponding counts of records.

m = pd.DataFrame(df_af_mp['country'].value_counts()) 
m = m.rename(columns={'country': 'value'})
m['country'] = m.index 
m.index = range(len(m)) 

m 

Showing the code with seperated steps: 

 

posted on 2023-07-20 13:33  McDelfino  阅读(16)  评论(0)    收藏  举报