gpt4 book ai didi

python - 如果列内的值非空,则在 pandas 中创建一个新的派生列

转载 作者:行者123 更新时间:2023-12-01 02:30:03 25 4
gpt4 key购买 nike

我的输入数据是这样的

SL.NO   Name
1 KING BATA
2
3
4 AGS
5 FORMULA GROWTH
6
7 Bag

输出

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、空白和垃圾值?

最佳答案

使用numpy.where :

#If missing value is NaN
df['Value'] = np.where(df['Name'].isnull(), 'Present', 'Not Present')

或者:

#If missing value is empty string
df['Value'] = np.where(df['Name'].eq(''), 'Present', 'Not Present')

关于python - 如果列内的值非空,则在 pandas 中创建一个新的派生列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46929780/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com