Not able to create subset

df[df['Region'] == 'Western Europe' or 'Sub-Saharan Africa']

This isn’t working, I tried and, &, | operands as well, if I write only only region, then works, but otherwise it throws error.

df[(df['Region'] == 'Western Europe' ) | (df['Region'] == 'Sub-Saharan Africa' )]

1 Like

Thanks @sanjayk
Also, when we want to subset wherein we have a lot of values, so do we have to write it separately all the time, or there is any other way also?

There might be some compact way of writing it in fewer letters., but I’m not aware.

1 Like