Python With Excel and Text Strings
Pandas Dataframes
Let’s now see how to filter on multiple columns
Code:
import pandas as pd
df = pd.read_excel('europe_cities_by_sunshine.xlsx')
df[ (df['Year'] > 3000) & (df['Dec'] > 170) ]
Explanation:
We can see here that we’re filtering above 3000 and also filtering for Dec sunshine above 170, and we can see it only returns 3 rows. We have to put each unique filtering conditions in parenthesis, and put the “&” sign in the middle to make sure the dataframe takes both of them. We could even put 100 conditions together, and as long as there are parentheses and “&” in the middle between them, then it’ll work.