I am trying to find the max min rows of every column in a dataframe. I don't even know where to start. I think df.groupby with agg wont work because I need the whole row.
Here's a sample data
import pandas as pd
df = pd.DataFrame(
{'A': array([4, 9, 2, 3, 3, 5, 7, 0, 4, 6]),
'B': array([4, 2, 4, 8, 4, 3, 1, 6, 9, 2]),
'C': array([8, 1, 8, 1, 2, 2, 7, 5, 9, 8]),
'D': array([9, 4, 2, 8, 0, 3, 6, 9, 3, 8])}
)
Expected outout
A B C D
1 A max 9 2 1 4
7 A min 0 6 5 9
8 B max 4 9 9 3
6 B min 7 1 7 6
8 C max 4 9 9 3
1 C min 9 2 1 4
0 D max 4 4 8 9
4 D min 3 4 2 0
if there are multiple rows with same min/max value, it's okey if it returns any of those.
PS: I'd like it to retain the original index.