I would like to take the dictionary and use that to fill in missing values in a dataframe column. So the dictionary keys correspond to the index in the dataframe or a different column in the data frame and the values in the dictionary correspond to the value I would like to update into the dataframe. Here's a more visual example.
key_col target_col
0 w a
1 c NaN
2 z NaN
Dictionary I'd like to map into the dataframe
dict = {'c':'B','z':'4'}
I'd like the dataframe to look like
key_col target_col
0 w a
1 c B
2 z 4
Now I've tried a few different things. setting the index to key_col and then trying
df[target_col].map(dict)
df.loc[target_col] = df['key_col'].map(dict)
I know replace doesn't work because it requires I set a criteria on the values that need to be replaced. I would just like to update the value if the key_col/index has a data value.
