2

I have run the following code to get data from quandl and it works

    import quandl
    import pandas as pd
    fiddy_states = pd.read_html('https://simple.wikipedia.org/wiki/List_of_U.S._states')
    for abbv in fiddy_states[0][0][1:]:
    #print(abbv)
       print("FMAC/HPI_"+str(abbv))

I get the print of the dataset "FMAC/HPI_" but when I try to execute the following code.I get error message

api_key = open('quandl_api_key.txt','r').read()
fiddy_states = pd.read_html('https://simple.wikipedia.org/wiki/List_of_U.S._states')

main_df = pd.DataFrame()

for abbv in fiddy_states[0][0][1:]:
    query = "FMAC/HPI_"+str(abbv)
    df = quandl.get(query,authtoken=api_key)

    if main_df.empty:
        main_df = df
    else:
        main_df = main_df.join(df)

The error message I get is the following:

 6 for abbv in fiddy_states[0][0][1:]:
      7     query = "FMAC/HPI_"+str(abbv)
----> 8     df = quandl.get(query,authtoken=api_key)
      9 

NotFoundError: (Status 404) (Quandl Error QECx02) You have submitted an incorrect Quandl code. Please check your Quandl codes and try again.

I tried to run the code with authtoken like the following:

for abbv in fiddy_states[0][0][1:]:
    query = "FMAC/HPI_"+str(abbv)
    df = quandl.get(query)

but still I get the same error. Please help

Rohail
  • 75
  • 1
  • 11

1 Answers1

0

The shape of fiddy_states is a bit complicated, because it is a list containing one element containing a dataframe with MultiIndex. Even more confusing is that the MultiIndex contains columns with the same name.

I could get data with this:

for abbv in fiddy_states[0]['Abbr']['Abbr']: 
    quandl.get('FMAC/HPI_'+abbv)
Aditya Santoso
  • 1,031
  • 6
  • 19