I am trying to replace all the values in my dataframe (for specific columns) that are < 0
with a value of 0
.
I have tried this code, but it does not seem to be working for me:
df.loc[df[['col_1','col_2','col_3']] < 0, 'col_1','col_2','col_3'] = 0
When using this line of code, I get the following error:
AttributeError: 'int' object has no attribute 'loc'
I am not sure whether it is the code I am using that is halting me from accomplishing what I want to do.
Therefore, could someone kindly point me in the right direction?
Thank you - please see sample data and expected output below.
Sample data:
col_1 col_2 col_3
--------------------------
4 5 -1
-3 -4 5
2 -2 2
Anticipated Result:
col_1 col_2 col_3
--------------------------
4 5 0
0 0 5
2 0 2