2

I have a dataframe like this

Country   Year    GDP (bil)
USA       1970    1073
China     1970    92.6
India     1970    62.42
Spain     1970    40.99
France    1970    148.5
USA       1980    2857
China     1980    191.1
India     1980    186.3
Japan     1980    1105
S.Korea   1980    64.98
Singapore 1980    11.9
USA       1990    5963
China     1990    360.9
India     1990    321
Thailand  1990    85.34
Singapore 1990    36.14

I would like to subset the data and get the GDP for USA, China and India in all these years. And another question, suppose I have GDP data of 200 countries every year and I am only interested in 50 countries. How can I subset the data? Thank you very much!

yatu
  • 86,083
  • 12
  • 84
  • 139

1 Answers1

3

you can use:

df[df.Country.isin(['USA', 'China', 'India'])][['Country', 'GDP']]

output:

enter image description here

kederrac
  • 16,819
  • 6
  • 32
  • 55