Create multiple dataframe using for loop in python 2.7

后端 未结 3 683
余生分开走
余生分开走 2021-01-26 01:00

I have a list of locations

[\"HOME\", \"Office\", \"SHOPPING\"]

and a pandas data frame \"DF\"

Start_Location  End_Location            


        
3条回答
  •  长发绾君心
    2021-01-26 01:41

    I got the answer which I was looking for

    import pandas as pd
    gbl = globals()
    for i in locations:
    gbl['df_'+i] = df[df.Start_Location==i]
    

    This will create 3 data frames df_HOME, df_office and df_SHOPPING

    Thanks,

提交回复
热议问题