I think in python is strongly not recommended创建字符串变量,因为这时生成的字符串不是琐碎.
那么最好是为字符串中的名字创建另一个列表,并使用zip
。
dframes_list = [economy, finance, language]
names = ['economy','finance','language']
for i, df in zip(names, dframes_list):
filename_attempt1 = "df_{}.csv".format(i)
另一个想法是创建DataFrames的dict。
dframes_dict = {'economy': economy, 'finance': finance, 'language': language}
for i, df in dframes_dict.items():
filename_attempt1 = "df_{}.csv".format(i)
If need working with dict of DataFrame
s use:
for k, v in dframes_dict.items():
v = v.set_index('date')
#another code for processing each DataFrame
dframes_dict[k] = v