Here is the sample dataframe.
data = [['United Kingdom', 'High income'], ['Albania', 'Upper middle income'], ['Russia', 'Upper middle income'], ['Afganistan','Low income'], ['USA','High income']]
df = pd.DataFrame(data, columns = ['Country', 'Income Group'])
Here I was trying to return only countries with high income and upper middle income:
df = np.where(df['Income Group'] == 'High income' & df['Income Group'] == 'Upper middle income')
Here is the output:
TypeError: tuple indices must be integers or slices, not str
But if you use the same with other column works fine:
df = np.where(df['Country'] == 'USA')
What is the problem with column 'Income Group'?
Very appreciate for any help
()around each condition