python - 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().
请帮助解决方案,在此先感谢
解决方案
推荐阅读
- python-3.x - PyQt5:Qstyle.CC_ScrollBar 呈现在错误的位置
- c# - 在 C# 中创建一个 ErrorProvider 数组
- cuda - cudaGetDeviceCount 返回错误:1 个无效参数
- python - 如何在循环浏览包含不同页数的 URL 时抓取分页表
- ios - React Native:图像 uri 不加载(仅在 iOS 中)
- neo4j - 在非常大的图上收集和排序节点的查询优化
- excel - 如何防止 range.select 上的错误 1004?
- bash - 在 csv 中添加从 Bash 中上一列中的数据创建的列
- node.js - Autodesk Forge:工业建筑演示桶不工作
- r - 如何更改水平 Plotly 条形图中的轨迹顺序?