From your example, it's not entirely clear what you want your DataFrames to contain.
So, here's some code that creates 3 DataFrames called DF1
, DF2
, & DF3
.
Each with 1-4*idx
as the sole column.
Please clarify if you wanted something else.
import pandas as pd
# Need to track the created DataFrames in some way. Using a dict here.
df_dict = dict()
for idx in [1, 2, 3]: # Using list 1,2,3, but could be changed back to l or range().
df_dict['DF'+str(idx)] = pd.DataFrame([1, 2, 3, 4])*idx
# This adds the key/value pairs as variables to the __locals__ dict.
# Generally not best practice.
locals().update(df_dict)
print(DF1)
print(DF2)
print(DF3)
In the above code, DFx is created in a dictionary to trace their creation, and then I add them to the locals dictionary. I would not write code like this.
My recommendation is to just use the generated dictionary (df_dict) directly.
Also, you can use multilevel/multidimensional DataFrames to probably solve whatever problem you would be using this for idx in range(x)
for. If you provide more detail I may be able to suggest better methods.
Cheers!