I would like to reduce my code. So instead of 2 lines I would like to select rows by 3 conditions on 2 columns. My DataFrame contains Country's population between 2000 and 2018 by granularity (Total, Female, Male, Urban, Rural)
Zone Granularity Year Value
0 Afghanistan Total 2000 20779.953
1 Afghanistan Male 2000 10689.508
2 Afghanistan Female 2000 10090.449
3 Afghanistan Rural 2000 15657.474
4 Afghanistan Urban 2000 4436.282
20909 Zimbabwe Total 2018 14438.802
20910 Zimbabwe Male 2018 6879.119
20911 Zimbabwe Female 2018 7559.693
20912 Zimbabwe Rural 2018 11465.748
20913 Zimbabwe Urban 2018 5447.513
I would like all rows of the Year 2017 with granularity Total AND Urban. I tried something like this below but not working but each condition working well in separate code.
df.loc[(df['Granularity'].isin(['Total', 'Urban'])) & (df['Year'] == '2017')]
Thanks for tips to help
df['Year'] == 2017is working good but alsodf['Year'] == '2017'and the only way to have result is to use the quote as Int fordf.loc[df['Year'] == '2017']df.dtypesin the questiondf1= df[df['Granularity'].isin(['Total', 'Urban'])].reset_index(drop=True)and thendf3= df1[df1['Year'] == '2017'].reset_index(drop=True)df['Year'].unique()?