Home > Enterprise >  Creating N dataframes from a list
Creating N dataframes from a list

Time:04-20

I want to create n DataFrames using the value s as the name of each DataFrame, but I only could create a list full of DataFrames. It's possible to change this list in each of the DataFrames inside it?

#estacao has something like [ABc,dfg,hil,...,xyz], and this should be the name of each DataFrame
   estacao = dados.Station.unique()
   for s,i in zip(estacao,range(126)):
     estacao[i] = dados.groupby('Station').get_group(s)

CodePudding user response:

I'd use a dictionary here. Then you can name the keys with s and the values can each be the dataframe corresponding to that group:

groups = dados.Station.unique()
groupby_ = datos.groupby('Station')

dataframes = {s: groupby_.get_group(s) for s in groups}

Then calling each one by name is as simple as:

group_df = dataframes['group_name']
  • Related