我的输入数据是这样的
SL.NO Name
1 KING BATA
2
3
4 AGS
5 FORMULA GROWTH
6
7 Bag
Output
SL.NO Name Value
1 KING BATA Present
2 Not Present
3 Not Present
4 AGS Present
5 FORMULA GROWTH Present
6 Not Present
7 Bag Present
如何处理 pandas 中的 null、空白和垃圾值?
Use numpy.where https://docs.scipy.org/doc/numpy/reference/generated/numpy.where.html:
#If missing value is NaN
df['Value'] = np.where(df['Name'].isnull(), 'Present', 'Not Present')
Or:
#If missing value is empty string
df['Value'] = np.where(df['Name'].eq(''), 'Present', 'Not Present')
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)