首页 > 解决方案 > python中有一个函数可以解决我的要求吗

问题描述

我有一个数据框

    dff.head()
+---+----------+-----------------+--------------+------------+
|   | owner_id | purchase_points | return_point | push_toke  |
+---+----------+-----------------+--------------+------------+
| 0 |      123 |            77.0 |          0.0 |            |
| 1 |      546 |             0.0 |         16.0 | Abc97grwe  |
| 2 |      789 |             5.0 |         15.0 | cst84ask   |
| 3 |      697 |            89.0 |          6.0 | abc7532asd |
+---+----------+-----------------+--------------+------------+

我正在尝试获取一个状态列来说明purchase_point是否> 0然后说“已购买”,如果返回点> 0并且push_token!= np.nan我想要“是的,从未购买过”,然后说“否”

我尝试了以下 if 循环,但发现以下错误:

def my_fun(organic, seeded, push_token):
if dff['purchase_points'] > 0: 
    return 'Yes Answered'
elif [dff['return_point'] > 0 | dff['push_token'] == np.nan]:
    return 'Yes, Never answered'
else:
    return 'No'
dff['status_1'] = dff.apply(my_fun('organic', 'seeded', 'push_token'))

错误:

ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().

请帮助解决方案,在此先感谢

标签: pythonpandasif-statement

解决方案


推荐阅读