0

I am trying to create multiple dataframes from the existing dictionaries. But after the loop finishes, the dataframes are not saved/made.

L1 = ['A','B','C',]
D1 = {'A':[1,2,3],'B':[4,5,6],'C':[7,8,9]}
D2 = {'A':['aa','bb','cc'],'B':['dd','ee','ff'],'C':['gg','hh','ii']}
D3 = {'A':['100','101','102'],'B':['103','104','105'],'C':['106','107','108']}
for each in L1:
    each = pd.DataFrame({(each+'1'):D1[each],(each+'2'):D2[each]},index=D3[each])
print (A)

Error message

NameError: name 'A' is not defined

I know the dataframe is once created since if I print/show the dataframe within the loop then it's ok.

But I want all dataframes to be saved so I can use later. Appreciate the help!

pome
  • 79
  • 1
  • 3
  • You're trying to print something that isn't defined (`A`). Are you perhaps trying to print something else? – roelofs Jan 04 '18 at 05:49
  • well you are just reassigning the variable `each`. For the three iteration of your code, `each` will first be 'A', then pd.DF, then 'B', and so on – Chris Jan 04 '18 at 05:49
  • yeah, I thought each iteration is gonna create a new dataframe and it will be saved. Then what is the good way to achieve it? – pome Jan 04 '18 at 07:43

0 Answers0