Для меня рабочий раствор без чека NaN
с:
df['item'] += ' box'
print (df)
id qty item
0 1 700 CB04 box
1 2 500 NaN
2 3 1500 AB01 box
Решения с чеком NaN
с:
Использование notna
с loc
df.loc[df['item'].notna(), 'item'] += ' box'
#for oldier pandas versions
#df.loc[df['item'].notnull(), 'item'] += ' box'
print (df)
id qty item
0 1 700 CB04 box
1 2 500 NaN
2 3 1500 AB01 box
Или numpy.where
:
df['item'] = np.where(df['item'].notna(), df['item'] + ' box', df['item'])
#df['item'] = np.where(df['item'].notnull(), df['item'] + ' box', df['item'])