pandas and NumPy 3 cheatsheet
pandas and NumPy 3: Selecting and filtering
8 common pandas and NumPy 3 tasks.
Select columns
Pick one column as a Series, or several as a DataFrame.
df["name"]
df[["name", "age"]]
Filter rows
Keep rows that meet conditions. Combine them with & and |, each in parentheses.
df[(df["age"] > 30) & (df["country"] == "UK")]
Filter with a string expression
Write conditions as readable text.
df.query("age > 30 and country == 'UK'")