I have a scenario where I have a CSV file having below data:
Host, Time Up, Time OK
server1.test.com:1717,100.00% ,100.00%
server2.test.com:1717,100.00% ,100.00%
I am trying to compare column values in all rows:
- if
col1 <= col2
then it should print the value ofcol1
in a newcol3
- if
col1 > col2
then printcol2
value incol3
.
Example:
Time Up(col1), Time OK(col2), Total(col3)
100% 100% 100%
100% 95% 95%
95% 100% 95%
I searched through internet and was unable to find any case. Is there any way to achieve this ?
EDIT2 : code-
import pandas as pd
df = pd.read_csv('3.csv',skipfooter=1)
df2 = pd.read_csv('4.csv',skipfooter=1)
combined = pd.merge(df[['Host',' Time Up']],df2[['Host',' Time OK']], on='Host')
combined[' Time OK'] = combined[' Time OK'].apply(lambda x: x.split('(')[0])
combined[' Time Up'] = combined[' Time Up'].apply(lambda x: x.split('(')[0])
combined.to_csv('combined.csv',index=False)
df =pd.read_csv('combined.csv', skipfooter=1)
col1 = df[' Time Up']
col2 = df[' Time OK']
df['Total'] = col1.where(col1 <= col2, col2)
df.to_csv('combined.csv',index=False)