pandas and NumPy 3 · Cleaning and transforming

Add a column based on a condition

Choose one of two values per row.

df["group"] = np.where(df["age"] >= 18, "adult", "minor")

Official pandas and NumPy 3 documentation

More cleaning and transforming commands

All cleaning and transforming commands · pandas and NumPy 3 cheatsheet

Was this page helpful?