Issue
I would like to remove values in the value1 and value2 column if the status column contains the string 'new'
Data
id date location status value1 value2
CC 1/1/2022 ny new 12 1
CC 4/1/2022 ny new 1 1
CC 7/1/2022 ny new 1 1
CC 10/1/2022 ny new 1 2
CC 1/1/2023 ny ok 1 2
Desired
id date location status value1 value2
CC 1/1/2022 ny new
CC 4/1/2022 ny new
CC 7/1/2022 ny new
CC 10/1/2022 ny new
CC 1/1/2023 ny ok 1 2
I do not want a NaN value, but I wish to have a blanks. Any suggestion is appreciated
Doing
df.loc[(df.status == 'new') 'value1', 'value2']= np.nan
Solution
Try with :
df.loc[(df.status == 'new'), ['value1', 'value2']] = ''
Answered By - BENY
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.