0

We have a pandas dataframe with data borrowed from here: Gapminder, country and income by year

We use dropna() and pivot_table() and a mask countries['Year'] >= 1990 to create a new table that looks like this:

Country   Afghanistan      Albania     ...            Zambia     Zimbabwe
Year                                   ...                               
1990     11738.881323   754.357011     ...       3383.108434  4140.904818
1991     12514.064579  1063.108731     ...       3561.065162  4133.270353
1992     14607.470776  1126.386166     ...       3806.918331  4758.081606
1993     18301.692593  1005.555801     ...       3740.561889  4911.218150
1994     21889.609655   908.485392     ...       4298.488561  4672.967020


Int64Index([1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000,
        2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011,
        2012, 2013, 2014, 2015],
       dtype='int64', name='Year')

Trying to do df[1990] returns a key error. What is the proper way to do it?

AturSams
  • 7,568
  • 18
  • 64
  • 98

0 Answers0