I am creating datasets using data from JSON API. The program below works but the pandas datasets cannot be referenced using the object names in list (df1 or dff1) but only when they are referenced as list items: dct1(1). I would love to learn why this is happening or maybe there is an error in the code.
dct1 = ['df1', 'df2', 'df3', 'df4']
dct2 = ['dff1', 'dff2', 'dff3', 'dff4']
dct3 = ['file1', 'file2', 'file3','file4']
for i in range(0,4):
off=1000*i
url = 'https://data.cms.gov/data-api/v1/dataset/7b181182-828c-4fa4-91bd-641759f6eddd/data?size=1000&offset={0}'.format(off)
dct2[i]=pd.read_json(url)
dct3[i]= 'https://data.cms.gov/data-api/v1/dataset/7b181182-828c-4fa4-91bd-641759f6eddd/data?size=1000&offset={0}'.format(off)
dct1[i]=pd.read_json(dct3[i])
dct1[1].head(3)
Out[64]:
Year State_Name ... Avg_Risk_Score_AGND Person_Years_AGND
0 2020 Kentucky ... 1.08687 5509.67
1 2020 Kentucky ... 1.05350 871.25
2 2020 Kentucky ... 0.96509 1290.42
print(df1)
NameError: name 'df1' is not defined
print(dff1)
NameError: name 'dff1' is not defined**