python - Replace NaN's in one column with string, based on value in another column - Stack Overflow

PHOTO EMBED

Tue Dec 21 2021 07:14:03 GMT+0000 (Coordinated Universal Time)

Saved by [deleted user] #python

In [5]:

d.loc[(d['A'].isnull()) & (d.B == 't3'), 'A']='new_val'

d

Out[5]:

         A   B
0      NaN  t1
1       t2  t2
2  new_val  t3
3       t3  t4
4  new_val  t3

[5 rows x 2 columns]
content_copyCOPY

https://stackoverflow.com/questions/21943688/replace-nans-in-one-column-with-string-based-on-value-in-another-column