I have a dataframe like as shown below
f = pd.DataFrame({'person_id': [101,101,101,201,201,201,203],
'test_id':[123,123,124,321,321,321,456],
'los_24':[0.3,0.7,0.6,1.01,2,1,2],
'los_48':[1,0.2,0.4,0.7,11,2,3],
'in_24':[21,24,0.3,2.3,0.8,23,1.001],
'in_48':[11.3,202.0,0.2,0.3,41.0,47,2],
'test':['A','B','C','D','E','F','G']})
I would like to replace all values less than 1 with value 1 under columns like los_24,los_48,in_24,in_48
I tried the below
f['los_24'] = np.where((f.los_24 < 1.0),1,f.los_24)
f['los_48'] = np.where((f.los_48 < 1.0),1,f.los_48)
f['in_24'] = np.where((f.in_24 < 1.0),1,f.in_24)
f['in_48'] = np.where((f.in_48 < 1.0),1,f.in_48)
But you can see am writing the same line of code multiple times with different column names.
In real data, I have more than 10 columns to replace values. So, Is there any other efficient and elegant way to write this?
I expect my output to be like as shown below
