In this python pandas program, we will calculate the frequency of each value of a series using pandas.
Steps to solve the program
- Import pandas library as pd.
- Create a series using pd.Series().
- Calculate the frequency of each value of a series using df.value_counts().
- Print the output.
import pandas as pd
df = pd.Series([3,0,3,2,2,0,3,3,2])
print(df)
result = df.value_counts()
print(result)
Output :
0 3
1 0
2 3
3 2
4 2
5 0
6 3
7 3
8 2
dtype: int64
3 4
2 3
0 2
dtype: int64