How to create multiple dataframes using multiple functions

前端 未结 2 1612
佛祖请我去吃肉
佛祖请我去吃肉 2021-01-02 16:54

I quite often write a function to return different dataframes based on the parameters I enter. Here\'s an example dataframe:

np.random.seed(1111)
df = pd.Dat         


        
2条回答
  •  暖寄归人
    2021-01-02 17:27

    A dictionary would be my first choice:

    variations = ([('Units Sold', list_one), ('Dollars_Sold',list_two), 
                  ..., ('Title', some_list)])
    
    df_variations = {}
    
    for i, v in enumerate(variations):
         name = v[0]
         data = v[1]
         df_variations[i] = some_fun(df, name, data)
    

    You might further consider setting the keys to unique / helpful titles for the variations, that goes beyond something like 'Units Sold', which isn't unique in your case.

提交回复
热议问题