Given a data frame:
Text Name
0 aa bb cc Paul
1 ee ff gg hh NA
2 xx yy NA
3 zz zz zz Anton
I want to replace only the cells in column "name" where values are "NA" with the first 3 words from the corresponding row in column "text"
Desired output:
Text Name
0 aa bb cc Paul
1 ee ff gg hh ee ff gg
2 xx yy xx yy
3 zz zz zz Anton
My attempt failed:
[' '.join(x.split()[:3]) for x in df['Text'] if df.loc[df['Name'] == 'NA']]