Python Practice › Pandas Programs › Program 23

Frequency of each value

EasyPandas Programs · 23 of 95

Write a pandas program to count each value.

Advertisement
Input
[3, 0, 3, 2, 2, 0, 3, 3, 2]
Output
0    2
2    3
3    4
Name: count, dtype: int64

Approach

  1. value_counts().

Solution

Python
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
Advertisement

Learn the concept

New to this topic? Read the lesson, then come back.

More pandas programs

← All 95 Pandas Programs