2

Am not sure if my quest is well framed but here it is.

here in this code i read the csv file and assign it to the variable australia_analysis specifying that the location column should be AUS

this is the output when i print it

How can i assign the dataframe to the variable under two conditions that the location should be AUS and the subject should be MEASLES so that i only get rows that satisfy the condition

Mikko Ohtamaa
  • 82,057
  • 50
  • 264
  • 435
David manga
  • 89
  • 1
  • 5
  • 1
    Does this answer your question? [Pandas: Filtering multiple conditions](https://stackoverflow.com/questions/48978550/pandas-filtering-multiple-conditions) – Rodalm May 29 '22 at 17:52

2 Answers2

2

You can combine multiple conditions with &:

loaded_data.loc[(loaded_data['LOCATION'] == 'AUS') & (loaded_data['SUBJECT'] == 'MEASLES')]
oriel9p
  • 298
  • 2
  • 5
1

You can filter based on multiple columns using this code

import pandas as pd
df = pd.DataFrame([{"a":1,"b":1},{"a":1,"b":2},{"a":2,"b":2},{"a":2,"b":1}])
df2 = df[(df["a"] ==1) & (df["b"]==2)]