unique()

noun

say it: “yoo-NEEK” /juˈnik/

A pandas method that gives each different value in a column once, with the repeats left out.

What does unique() do in pandas?

unique() lists each different value in a column once, in the order it first appears. It's where you spot one thing spelled two ways, such as Produce and produce, that cleaning has to make match.

import pandas as pd
sales = pd.DataFrame({"category": ["produce", "honey", "Produce", "honey"]})
sales["category"].unique()    # ['produce', 'honey', 'Produce']

In a sentence

  • “He used unique() to list every vendor that sold that Saturday.”
  • “unique() showed both 'Produce' and 'produce' in the category column.”

Level: Apprentice · More Python terms at this level

Updated