In an old interpreted language used by astrophysicists a few years ago for data processing, SuperMongo, which has been superseded by Python now, it was possible to do things like that (for clarity, I write pseudo code, not real SuperMongo):
mylist = [bar,foo]
for df in mylist:
bar = pd.read_csv(df+".csv")
for i = 1 to n:
bar+"_"+i = bar * i
You've grab the idea: you could create an instance (for example, a Pandas DataFrame) from the concatenation of the name of others in a loop, or to build a string indicating a file name, for example. I work with many DataFrame and my code would be far more readable, mistake-proof, and easy to write, if I could loop on them. I sometimes use some things like lists of lists:
my_list = [[df1, df1_something, df1_another_thing,"df1.csv"],
[df2, df2_something, df2_another_thing,"df2.csv"],
[dfothername, dfothername_something, dfothername_another_thing,"df1.csv"],
...
]
for df in my_list:
df[2]=some_function(df[1])
...
But it's still not perfect.
Is there a way to achieve what I've showed in pseudo-code in python ?
Edit: The question is somehow a duplicate. To be short, you can do something like this:
dic = {}
for name in namelist:
dic[name]=pd.read_csv(name+".csv")
dic['othername']=pd.DataFrame(...)
for name in dic.keys():
dic[name+"_processed"]=process(dic[name])
Or, for the last line, depending on what is the most convenient in context:
dic_processed = {}
for name in dic.keys():
dic_processed[name]=process(dic[name])