【发布时间】:2019-05-10 13:56:41
【问题描述】:
我已经查看了很多关于该错误的问题,但我没有找到任何可以帮助解决我的问题的方法。 我有 DataFrame:
Errors.dtypes
日期对象
小时 int64
分钟 int64
第二个 int64
机器对象
定位对象
ErrorVal 对象
持续时间 int64
数据类型:对象
和列表列表:
list_of
[[datetime.date(2019, 1, 27), 'MAS1', 'OBS', '15'],
[datetime.date(2019, 1, 10), 'MAS1', 'OBS', '21'],
...
现在,我想根据 list_of 在 Errors 中添加新列 - 当列 'Date'、'Machine'、'Position'、'ErrorVal' 在list_of - 新列“AboveAv”的值为 True,否则为 False。我试过这个:
Errors['AboveAv'] = True if ([Errors['Date'],Errors['Machine'],Errors['Position'],Errors['ErrorVal']] in tmp) else False
但是当我尝试运行此程序时出现错误:ValueError: 系列的真值不明确。使用 a.empty、a.bool()、a.item()、a.any() 或 a.all()。
我该如何处理?如果该行包含在 list_of
示例:
数据帧错误:
Date Hour Minute Second Machine Position ErrorVal Duration
1 2019-01-12 22 50 30 MAS1 POS 76 94
2 2019-01-14 3 13 21 MAS1 POS 76 87
3 2019-01-21 3 14 54 MAS1 POS 14 19
4 2019-01-22 3 59 57 MAS1 POS 76 87
5 2019-01-25 4 1 30 MAS1 POS 14 12
6 2019-01-27 11 15 28 MAS1 POS 76 63
list_of:
[[datetime.date(2019, 1, 21), 'MAS1', 'POS', '14'],
[datetime.date(2019, 1, 22), 'MAS1', 'POS', '76'],
[datetime.date(2019, 1, 27), 'MAS1', 'POS', '76']]
我的新数据框:
Date Hour Minute Second Machine Position ErrorVal Duration AboveAv
1 2019-01-12 22 50 30 MAS1 POS 76 94 False
2 2019-01-14 3 13 21 MAS1 POS 76 87 False
3 2019-01-21 3 14 54 MAS1 POS 14 19 True
4 2019-01-22 3 59 57 MAS1 POS 76 87 True
5 2019-01-25 4 1 30 MAS1 POS 14 12 False
6 2019-01-27 11 15 28 MAS1 POS 76 63 True
【问题讨论】:
-
如错误消息所述,您必须将
.empty、.bool()、.item()、.any()或.all()之一附加到您的系列。例如,..., Errors['ErrorVal']] in tmp).all() else False。