Reputation: 5097
I have a dataframe (df) that looks like:
Value
03/03/2014 3
03/03/2014 3
03/03/2014 6
03/03/2014 4
03/03/2014 5
03/03/2014 3
03/03/2014 5
03/03/2014 8
03/03/2014 7
04/03/2014 6
04/03/2014 9
04/03/2014 2
04/03/2014 3
04/03/2014 10
04/03/2014 6
04/03/2014 7
04/03/2014 5
04/03/2014 7
05/03/2014 1
05/03/2014 9
05/03/2014 5
05/03/2014 9
05/03/2014 2
05/03/2014 9
05/03/2014 6
05/03/2014 8
05/03/2014 1
06/03/2014 9
06/03/2014 10
06/03/2014 9
06/03/2014 6
06/03/2014 8
06/03/2014 5
06/03/2014 10
06/03/2014 5
06/03/2014 10
07/03/2014 8
07/03/2014 7
07/03/2014 4
07/03/2014 5
07/03/2014 9
07/03/2014 2
07/03/2014 3
07/03/2014 2
07/03/2014 4
I would like to add a new column DayMin
which contains the minimum value for each day in column Value and would look like:
Value DayMin
03/03/2014 3 3
03/03/2014 3 3
03/03/2014 6 3
03/03/2014 4 3
03/03/2014 5 3
03/03/2014 3 3
03/03/2014 5 3
03/03/2014 8 3
03/03/2014 7 2
04/03/2014 6 2
04/03/2014 9 2
04/03/2014 2 2
04/03/2014 3 2
04/03/2014 10 2
04/03/2014 6 2
04/03/2014 7 2
04/03/2014 5 2
04/03/2014 7 2
05/03/2014 1 1
05/03/2014 9 1
05/03/2014 5 1
05/03/2014 9 1
05/03/2014 2 1
05/03/2014 9 1
05/03/2014 6 1
05/03/2014 8 1
05/03/2014 1 1
06/03/2014 9 5
06/03/2014 10 5
06/03/2014 9 5
06/03/2014 6 5
06/03/2014 8 5
06/03/2014 5 5
06/03/2014 10 5
06/03/2014 5 5
06/03/2014 10 5
07/03/2014 8 2
07/03/2014 7 2
07/03/2014 4 2
07/03/2014 5 2
07/03/2014 9 2
07/03/2014 2 2
07/03/2014 3 2
07/03/2014 2 2
07/03/2014 4 2
I can see I can use df['DayMin']= df['Value'].min()
to get the column global minimum. But I can't see how to do this for each day and return it to the df.
Upvotes: 1
Views: 32
Reputation: 150735
You can use groupby().transform
:
df['DayMin'] = df.groupby(level=0)['Value'].transform('min')
Upvotes: 3