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
- Count missing values
- Drop rows with missing values
- Fill missing values
- Remove duplicate rows
- Rename columns
- Drop columns
All cleaning and transforming commands · pandas and NumPy 3 cheatsheet