0

I have a list as below

list = ['df1','df2','df3']

I want to create empty dataframes with these list items and I have tried the below

for i in list:
    str(i) = pd.DataFrame()

I would like to get 3 pandas dataframe created

df1
df2
df3

I have done an extensive search but not able to find a solution.

Ahamed Moosa
  • 1,395
  • 7
  • 16
  • 30

1 Answers1

1

Use the exec function:

l = ['df1','df2','df3']
for x in l:
    exec('%s = pd.DataFrame()' %x)
It_is_Chris
  • 13,504
  • 2
  • 23
  • 41