【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:

浙公网安备 33010602011771号