Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to apply cummax logic from column 5 in a data frame

User_id name 1 2 3 4 5 
 100      a   10   0.    12  0.    0
 200.     d   0   0.     11  0.    0
 300.     c.  0   0.     11  0.    0

I want to apply cummax log from day 1 column on row level axis=1 I have tried model_cluster_one.loc[:, 'day1':'day5 '].cummax(axis=1)

but it doesn't work and make the changes to the data frame what am I missing here

like image 512
sruuu Avatar asked Jan 18 '26 11:01

sruuu


1 Answers

I think you need assign output back:

model_cluster_one.loc[:, 'day1':'day5 '] = model_cluster_one.loc[:, 'day1':'day5 '].cummax(axis=1)

Or filter columns by positions with DataFrame.iloc and assign back:

model_cluster_one.iloc[:, 2:] = model_cluster_one.iloc[:, 2:].cummax(axis=1)

print (model_cluster_one)
   User_id name     1     2     3     4     5
0      100    a  10.0  10.0  12.0  12.0  12.0
1      200    d   0.0   0.0  11.0  11.0  11.0
2      201    c   0.0   0.0  11.0  11.0  11.0
like image 131
jezrael Avatar answered Jan 21 '26 01:01

jezrael



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!