Issue
I have a dataframe df
:
A B C
1 'x' 15.0
2 'y' NA
3 'z' 25.0
And a dictionary dc
:
dc = {'x':15,'y':35,'z':25}
I want to fill all nulls in column C of the dataframe using values of column B from the dictionary. So that my dataframe will become this:
A B C
1 'x' 15
2 'y' 35
3 'z' 25
Solution
dc = {'x':15,'y':35,'z':25}
df['C'] = df.C.fillna(df.B.map(dc))
df
# A B C
#0 1 x 15.0
#1 2 y 35.0
#2 3 z 25.0
Answered By - Psidom
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.