I have a DataFrame that looks like this:
data
a b
1 1 0.1
2 0.2
3 0.3
2 1 0.5
2 0.6
3 0.7
and I want to find the minimum value for each level of a
ignoring the b
level, so as an output I'm looking for something like
a min
1 0.1
2 0.5
To find minimum value of every row in DataFrame just call the min() member function with DataFrame object with argument axis=1 i.e. It returned a series with row index label and minimum value of each row.
min() function to find the minimum value among the underlying data in the given series object. Output : Now we will use Series. min() function to find the minimum value of the given series object.
The simpliest is use min
with parameter level=0
:
print (df.data.min(level=0).reset_index(name='min'))
a min
0 1 0.1
1 2 0.5
If need output as df
and only one column df
:
print (df.min(level=0))
data
a
1 0.1
2 0.5
Or groupby
by first level with aggregating min
:
print (df.groupby(level=0).data.min().reset_index(name='min'))
a min
0 1 0.1
1 2 0.5
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With