0

I have the following dataframe:

     date   Total       CA        Can        MDlt       Al     WDlt  \
0   2012-01-01 21,250.000  6,013.000 3,558.000  3,270.000  2027   1,880.000   
1   2012-02-01 21,250.000  6,350.000 3,385.000  3,365.000  2055   1,690.000   
2   2012-03-01 21,113.000  6,213.000 3,350.000  3,300.000  2020   1,800.000   
3   2012-04-01 21,850.000  6,457.000 3,493.000  3,435.000  2119   1,805.000   
4   2012-05-01 24,041.000  7,228.000 3,675.000  3,785.000  2392   2,031.000   
..         ...        ...        ...       ...        ...   ...         ...   
123 2022-04-01 27,900.000  9,116.000 4,372.000  3,843.000  2114   2,082.000   
124 2022-05-01 31,400.000 10,264.000 5,367.000  3,879.000  2382   2,332.000   
125 2022-06-01 32,600.000 10,658.000 5,135.000  4,452.000  2472   2,428.000   
126 2022-07-01 33,000.000 10,437.000 5,159.000  4,975.000  2474   2,460.000   
127 2022-08-01 34,200.000 11,214.000 5,455.000  4,622.000  2598   2,506.000   

    NUEE      SUEE  
0   1,995.000 2,507.000  
1   1,985.000 2,420.000  
2   1,984.000 2,446.000  
3   2,076.000 2,465.000  
4   2,063.000 2,867.000  
..        ...       ...  
123 3,086.000 3,287.000  
124 3,432.000 3,744.000  
125 3,576.000 3,879.000  
126 3,788.000 3,707.000  
127 3,720.000 4,085.000 

My question is I want to create three dataframes as below: -The first one only includes the rows which matches at min() i.e all row cells are minimum every year. -The second one is the same the first one but matched at max(). -The third one only includes the row entirely matched at max().

I tried :

indx = df.groupby('year')[df.columns[1:]].idxmin
df.loc[indx ]
df.loc[indx ].sort_index()

But I failed

sazaki
  • 21
  • 5

0 Answers0