python - Multiple graphs in a single plot with a for loop -


i trying display in single plot n graphs, n being number of u.s states number.

the compiler doesn't 2 linesx[j] = df['date'] y[j] = df['value']

=> typeerror: 'nonetype' object not subscriptable

import quandl import pandas pd import matplotlib.pyplot plt  states = pd.read_html('https://simple.wikipedia.org/wiki/list_of_u.s._states') j = 0 x = [] y = []  in states[0][0][1:]:         df = quandl.get("fmac/hpi_"+i, authtoken="yourtoken" )         df = df.reset_index(inplace=true, drop=false)         x[j] = df['date']         y[j] = df['value']         j += 1  plt.plot(x[j],y[j]) plt.xlabel('date') plt.ylabel('value') plt.title('house prices') plt.legend() plt.show() 

your problem particular error using inplace argument , assigning variable df. when using inplace argument equals true, return none.

print(type(df.reset_index(inplace=true, drop=false))) nonetype  print(type(df.reset_index(drop=false))) pandas.core.frame.dataframe 

use either inplace=true , don't assign df:

df.reset_index(inplace=true, drop=false) 

or use default inplace=false , assign variable df

df = df.reset_index(drop=false) 

there other logic errors here.

edit working chart (limit 20 testing)

for in states[0][0][1:20]:         df = quandl.get("fmac/hpi_"+i, authtoken="yourtoken" )         df.reset_index(inplace=true, drop=false)         plt.plot('date','value',data=df)   # plt.plot(x[j],y[j]) plt.xlabel('date') plt.ylabel('value') plt.title('house prices') plt.show() 

enter image description here


Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

thorough guide for profiling racket code -