0
$\begingroup$

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?

$\endgroup$
0
$\begingroup$

Try this:

A.loc[A.for_analysis & (A.index.isin(B.index)) , content_preprocessed] = B.content_preprocessed
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.