Replace column in a dataframe with another column based on index I have the following dataframe A:
        score   content  content_preprocessed   for_analysis
1         5       a             aaa                 True
2         5       b             NaN                 False
3         1       c             ccc                 True
4         1       d             ddd                 True

I need to replace content_preprocessed column with the following new column from dataframe B:
        content_preprocessed
1              aaz  
3              ccf     
4              ddo   

which contains new values for content_preprocessed where for_analysis is set to True. The values for content_preprocessed should remain NaN if the corresponding for_analysis is False.
How do I do that?
Try this:
A.loc[A.for_analysis &amp; (A.index.isin(B.index)) , content_preprocessed] = B.content_preprocessed