Python Practice › Pandas Programs › Program 23
Frequency of each value
Write a pandas program to count each value.
Input
[3, 0, 3, 2, 2, 0, 3, 3, 2]
Output
0 2 2 3 3 4 Name: count, dtype: int64
Approach
value_counts().
Solution
import pandas as pdprint(pd.Series([3, 0, 3, 2, 2, 0, 3, 3, 2]).value_counts().sort_index())Output
0 2 2 3 3 4 Name: count, dtype: int64
Learn the concept
New to this topic? Read the lesson, then come back.