Q:

How to groupby column for keep data in new dataframe and sort by datetime in pandas with Python 2.7

I want to groupby column "Location" of my df to keep in new_df and sort by column "datetime" with Python 2.7
This is my df :
>>df
       DateTime     Product     Location       Value
0    12-07-2018           A           S1       1.313
1    12-07-2018           A           S2       3.089
2    12-07-2018           A           S3       1.890
3    12-07-2018           A           S4       3.136
4    12-07-2018           B           S1       3.258
5    13-07-2018           B           S2       3.113
6    13-07-2018           B           S3       2.651
7    13-07-2018           B           S4       2.135
8    13-07-2018           C           S1       1.555
9    14-07-2018           C           S2       2.009
10   14-07-2018           C           S3       1.757
11   14-07-2018           D           S1       1.808
12   14-07-2018           D           S2       1.511
13   15-07-2018           D           S3       2.265
14   15-07-2018           D           S4       2.356
15   15-07-2018           D           S5       2.950
16   15-07-2018           E           S1       3.300
17   16-07-2018           E           S2       3.110
18   16-07-2018           F           S1       2.068

I would like to seperate S1, S2, S3, S4,...(etc) in column "Location" and sort by datetime 
This is result that I need :
>>new_df_S1
       DateTime     Product     Location       Value
0    12-07-2018           A           S1       1.313
1    12-07-2018           B           S1       3.258
2    13-07-2018           C           S1       1.555
3    14-07-2018           D           S1       1.808
4    15-07-2018           E           S1       3.300
5    16-07-2018           F           S1       2.068

>>new_df_S2
       DateTime     Product     Location       Value
0    12-07-2018           A           S2       3.089
1    13-07-2018           B           S2       3.113
2    14-07-2018           C           S2       2.009
3    14-07-2018           D           S2       1.511
4    16-07-2018           E           S2       3.110

and another (new_df_S3, new_df_S4, new_df_S5, ...) 

Now I use this code for my result but my dataframe has 1000 rows or more. It use many time for search S1, S2, ... in row and keep to new_df :
> for r in range(len(df)) :
    if df.iloc[r,2] == "S1":
       new_df_S1.loc[len(new_df_S1)] = [ df.iloc[r, 0], df.iloc[r, 1], 
                                         df.iloc[r, 2], df.iloc[r, 3] ]
    elif df.iloc[r,2] == "S2":
       new_df_S2.loc[len(new_df_S2)] = [ df.iloc[r, 0], df.iloc[r, 1], 
                                         df.iloc[r, 2], df.iloc[r, 3] ]
    elif df.iloc[r,2] == "S3":
       new_df_S3.loc[len(new_df_S3)] = [ df.iloc[r, 0], df.iloc[r, 1], 
                                         df.iloc[r, 2], df.iloc[r, 3] ]
    elif df.iloc[r,2] == "S4":
       new_df_S4.loc[len(new_df_S4)] = [ df.iloc[r, 0], df.iloc[r, 1], 
                                         df.iloc[r, 2], df.iloc[r, 3] ]
    .
    .
    .

       and another (new_df_S5, new_df_S6, ...)

Is there a way to reduce the time for seperate S1, S2, S3, ... ?

A:

You can use this:
gp = df.groupby('Location')

#Create a dictionary of dataframes
new_df = dict(tuple(gp))

OR
Update to reset index for row 0...n
new_df={}
for n,g in gp:
    new_df[n] = g.reset_index(drop=True)

new_df['S1']    

Output:
      DateTime Product Location  Value
0   12-07-2018       A       S1  1.313
4   12-07-2018       B       S1  3.258
8   13-07-2018       C       S1  1.555
11  14-07-2018       D       S1  1.808
16  15-07-2018       E       S1  3.300
18  16-07-2018       F       S1  2.068

new_df['S2']

Output:
      DateTime Product Location  Value
1   12-07-2018       A       S2  3.089
5   13-07-2018       B       S2  3.113
9   14-07-2018       C       S2  2.009
12  14-07-2018       D       S2  1.511
17  16-07-2018       E       S2  3.110

.
.
.
new_df['S4']

