I have a df like this:
'62' '63' '64' code
0 20.03743333333333 26.869833333333325 24.724533333333333 82022
1 10.4041 31.236499999999996 29.091200000000004 82026
2 26.88743333333333 33.71983333333333 31.574533333333335 82099
3 19.820766666666664 17.65316666666666 25.507866666666668 82107
4 28.037433333333333 34.86983333333333 32.72453333333334 82193
5 20.754099999999998 27.586499999999994 25.441200000000002 82244
6 31.070766666666664 37.903166666666664 35.75786666666667 82281
7 14.770766666666665 21.603166666666663 19.45786666666667 82332
8 35.53743333333333 42.36983333333333 40.22453333333334 82397
9 41.637433333333334 48.46983333333333 46.324533333333335 82400
I want to get the minimum value of each column and their corresponding code in a dataframe, like this:
62 10.4041 82026
63 17.65316666666666 82107
64 19.45786666666667 82332
I've been trying with:
df62 = df.groupby(['code'])['62'].min()
df63 = df.groupby(['code'])['63'].min()
df64 = df.groupby(['code'])['64'].min()
But is not working.
Can you tell me a possible solution please?
You can try doing:
df.set_index('code').agg(['idxmin','min']).T
idxmin min
'62' 82026.0 10.404100
'63' 82107.0 17.653167
'64' 82332.0 19.457867