Skip to content Skip to sidebar Skip to footer

How To Assign A String Variable To A Dataframe Name

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','l

Solution 1:

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:]
fordfin tail_dfs:
  res_df = res_df.unionAll(df)

upd. even better option to union described in comment.

Post a Comment for "How To Assign A String Variable To A Dataframe Name"