本文介绍了如何将String变量分配给数据框名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我遇到了一个问题,它是一个for循环程序,如下所示:
I had a problem, which is a for loop program.like below:
list = [1,2,3,4]
for index in list:
new_df_name = "user_" + index
new_df_name = origin_df1.join(origin_df2,'id','left')
但是 new_df_name 只是变量和字符串类型。
but the "new_df_name" is just a Variable and String type.
如何实现这些目标?
推荐答案
我认为,您真正需要的是拥有一个数据框列表(不必使用任何特定名称),然后将它们全部合并在一起。
I assume, what you really need is to have a list of dataframes (which non necessary have any specific names) and then union them all together.
dataframes = [df1, df2, df3, etc... ]
res_df, tail_dfs = dataframes[0], dataframes[1:]
for df in tail_dfs:
res_df = res_df.unionAll(df)
upd。
甚至在评论中描述了更好的联盟选择。
upd.even better option to union described in comment.
这篇关于如何将String变量分配给数据框名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!