Использование DataFrame.loc
с логическим значением amsk, созданным Series.isna
:
results_DF.loc[results_DF['type'].isna(), 'method'] = 'BBBB'
#oldier pandas versions
#results_DF.loc[results_DF['type'].isnull(), 'method'] = 'BBBB'
Другое решение с numpy.where
:
results_DF['method'] = np.where(results_DF['type'].isna(), 'BBBB', results_DF['method'])
Или решение от @Jon Clements, спасибо:
results_DF['method'] = results_DF.where(results_DF['type'].notnull(), 'BBBB')
Sample
results_DF = pd.DataFrame({'method': ['a','s','d'],
'type':[np.nan, np.nan, 4]})
print (results_DF)
method type
0 a NaN
1 s NaN
2 d 4.0
results_DF.loc[results_DF['type'].isna(), 'method'] = 'BBBB'
print (results_DF)
method type
0 BBBB NaN
1 BBBB NaN
2 d 4.0