0

I imported CSV file with data about airports. Countries are in column "Country Name". I want to work only with data about Ukrainian, German and Polish airports. I filtered my data, but I only know how to pick one country. How I can filter my data for two or more desired countries? I'm using python 3.8.1.

My code:

filtered_data = df[df["Country Name"]=="Poland"]
print(filtered_data)
martineau
  • 119,623
  • 25
  • 170
  • 301
Edyficjum
  • 81
  • 6
  • or [How to filter Pandas dataframe using 'in' and 'not in' like in SQL](https://stackoverflow.com/questions/19960077/how-to-filter-pandas-dataframe-using-in-and-not-in-like-in-sql) – Graeme Jun 02 '20 at 17:50
  • 3
    You can use something like - "df.isin({'Country Name': ['Poland', 'German', 'Ukrainian']})" – Hussain Bohra Jun 02 '20 at 17:50

1 Answers1

1

I guess you need this

filtered_data = df[(df["Country Name"]=="Poland") | (df["Country Name"]=="Germany") | (df["Country Name"]=="Ukraine")]
print(filtered_data)

To specify multiple conditions, you need to combine the various conditions using boolean operators **(NOTE: & instead of and, | instead of or, so on)

paradocslover
  • 2,932
  • 3
  • 18
  • 44