0
data2 = data.drop('Indicator Name', axis=1, inplace=True)
data3 = data2.drop('Indicator Code', axis=1, inplace=True)
x = [ data3[x].mean() for x in data.loc[:, "1960" : "2017" ]]
y = data.loc[:, "1960" : "2017" ]
plt.plot(x, y, color='orange')

plt.title('GDP Per year form 1960 to 2017')
plt.show()

I want to plot the mean value of all the data from 1960 to 2017 but I'm getting an error when I try to get the mean values for each column to use them in the plot. What is the best approach to achieve that. Need help

 TypeError  Traceback (most recent call last)
 <ipython-input-63-ec5963e0529b> in <module>()
       1 data2 = data.drop('Indicator Name', axis=1, inplace=True)
       2 data3 = data.drop('Indicator Code', axis=1, inplace=True)
 ----> 3 x = [ data2[x].mean() for x in data.loc[:, "1960" : "2017" ]]
       4 y = data.loc[:, "1960" : "2017" ]
       5 plt.plot(x, y, color='orange')





<ipython-input-63-ec5963e0529b> in <listcomp>(.0)
          1 data2 = data.drop('Indicator Name', axis=1, inplace=True)
          2 data3 = data.drop('Indicator Code', axis=1, inplace=True)
    ----> 3 x = [ data2[x].mean() for x in data.loc[:, "1960" : "2017" ]]
          4 y = data.loc[:, "1960" : "2017" ]
          5 plt.plot(x, y, color='orange')

TypeError: 'NoneType' object is not subscriptable
  • Use a debugger and find out which object is considered to be NoneType. In python NoneType means Null. – emsimpson92 Jul 27 '18 at 21:48
  • See if [this question](https://stackoverflow.com/questions/216972/in-python-what-does-it-mean-if-an-object-is-subscriptable-or-not) helps. Essentially I suspect that `data2` is None here, due to the use of `inplace=True`. – ImportanceOfBeingErnest Jul 27 '18 at 23:28

0 Answers0