Link to home
Start Free TrialLog in
Avatar of Sean Girgis
Sean GirgisFlag for United States of America

asked on

Python - Pandas - DataFrame- update a column from another based on compare

#Python3.78 #Pandas #DataFrame

I have a dataframe servers.csv

I want to update rating1 from rating2 as follows: -

rating1 will be equal to rating2 when rating2 > rating1

servers.csv

outcome.csv



servers.csv file

------------

Server, rating1 , rating2
'Serv1' , 500.54,
'Serv2' , , 750.21
'Serv3' , 500, 750.35
'Serv4' , 999.99, 399


outcome.csv file
------------
Server, rating1 , rating2
'Serv1' , 500.54,
'Serv2' , 750.21 , 750.21
'Serv3' , 750.35, 750.35
'Serv4' , 999.99, 399

ASKER CERTIFIED SOLUTION
Avatar of David H.H.Lee
David H.H.Lee
Flag of Malaysia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Sean Girgis

ASKER

David,

Thanks,
this worked great., but I want to understand what the code <<df.columns = df.columns.str.strip()>> is doing?
what the code <<df.columns = df.columns.str.strip()>> is doing?
It just strips off the whitespace of the column for my testing purpose only.