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:
标签:based,Calculate,country,863,value,records,dataframe,names From: https://www.cnblogs.com/alex-bn-lee/p/17568077.html