Count the frequency a value occurs in Pandas dataframe

Pandas

import modules

import pandas as pd
import numpy as np

create dummy dataframe

raw_data = {'name': ['Willard Morris', 'Al Jennings', 'Omar Mullins', 'Spencer McDaniel'],
'age': [20, 20, 22, 21],
'favorite_color': ['blue', 'red', 'yellow', "green"],
'grade': [88, 92, 95, 70]}
df = pd.DataFrame(raw_data, index = ['Willard Morris', 'Al Jennings', 'Omar Mullins', 'Spencer McDaniel'])
df
age favorite_color grade name
Willard Morris 20 blue 88 Willard Morris
Al Jennings 20 red 92 Al Jennings
Omar Mullins 22 yellow 95 Omar Mullins
Spencer McDaniel 21 green 70 Spencer McDaniel

return the frequency of each unique value in 'age' column in Pandas dataframe

df.groupby('age').size()
 age  20    2  21    1  22    1  dtype: int64