0

I have a list of dataframes (it's just how I inherited them from an import) How do I write a loop to create individual dataframes from list of dataframes? Rather than doing it manually like this?

df1 = df[0] 
df2 = df[1] 
df3 = df[2] 
df4 = df[3] 
df5 = df[4] 
df6 = df[5]

I'm so dusty

counter = 0
n = counter+1

for i in range(0,len(df)-1):
  if counter==0:
    dfn = df[counter]
Henry Ecker
  • 34,399
  • 18
  • 41
  • 57

1 Answers1

0
df = [-1, -2, -3, -4, -5, -6]

for i in range(0, len(df)):
    globals()[f'df{i + 1}'] = df[i]

print(f'df1 = {df1}')
print(f'df2 = {df2}')
print(f'df3 = {df3}')
print(f'df4 = {df4}')
print(f'df5 = {df5}')
print(f'df6 = {df6}')

in console

df1 = -1
df2 = -2
df3 = -3
df4 = -4
df5 = -5
df6 = -6
wrxue
  • 158
  • 6