按列值等于Non的条件删除DataFrame中的行

2024-10-08 19:30:58 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个数据帧,其中有一列“status” 我试图删除“status”列中没有值的所有行。在

我是这样做的:

oppty_oppline.dropna(subset = ['status'])

但是“None”值没有被删除。 我这样验证:

^{pr2}$

结果:

array(['Cancelled by ', 'Cancelled by Customer',
       'Account not selected', None,
       'Won - Deliver & Validate by ', 'Lost',
       'Won - Deliver & Validate by Partner',
       'Won-Deliver&Validate by ',
       'Cancelled by ', 'Won by another',
       'Won- Deliver and Validate by Partner',
       'Won – Deliver & Validate by Partner'], dtype=object)

我看到'None'值不被视为字符串。在

有什么主意可以帮我吗?在

谢谢你


Tags: 数据nonepartnerbystatusvalidatearraysubset
1条回答
网友
1楼 · 发布于 2024-10-08 19:30:58

如果^{cd1>}值,则工作良好:

a = np.array(['Cancelled by ', 'Cancelled by Customer',
       'Account not selected', None])

oppty_oppline = pd.DataFrame({'status':a})
print (oppty_oppline)
                  status
0          Cancelled by 
1  Cancelled by Customer
2   Account not selected
3                   None

df = oppty_oppline.dropna(subset = ['status'])
print (df)
                  status
0          Cancelled by 
1  Cancelled by Customer
2   Account not selected

但是,如果字符串^{cd1>}需要按^{}删除行:

^{pr2}$
^{pr3}$

相关问题 更多 >

    热门问题