Issue
I want to change the value of each item in the column 'ageatbirth' to '1' if the 'race' is 2. In pseudocode:
If 'race' == 2 and 'ageatbirth' == 2:
'ageatbirth' == 1
Is there an easy way to do this for a very large dataset?
Solution
Use
m = df['race'].eq(2) & df['ageatbirth'].eq(2)
df['ageatbirth'] = df['ageatbirth'].mask(m, 1)
# or
df.loc[m, 'ageatbirth'] = 1
Answered By - Ynjxsjmh
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.