How to count unique items in pandas

PHOTO EMBED

Mon Apr 19 2021 08:41:49 GMT+0000 (Coordinated Universal Time)

Saved by @siddharth #python

import pandas as pd

# create a dataframe with one column
df = pd.DataFrame({"col1": ["a", "b", "a", "c", "a", "a", "a", "c"]})

# setting normalize=True
item_counts = df["col1"].value_counts(normalize=True)
print(item_counts)
content_copyCOPY

Count of unique items in pandas

https://www.educative.io/edpresso/how-to-count-unique-items-in-pandas