【发布时间】:2019-02-09 19:37:22
【问题描述】:
我有两个这样的数据框:
df1:
Email DateTimeCompleted
2@2.com 2019-02-09T01:34:44.591Z
df2:
Email DateTimeCompleted
b@b.com 2019-01-29T01:34:44.591Z
2@2.com 2018-01-29T01:34:44.591Z
如何在 df2 中查找 Email 值并比较 DateTimeCompleted 大于 TODAY(减去)90 天的位置并将 df1 行数据附加到 df2 中?有时添加 df2 可以是空的,如果这会有所不同。
df2 更新后如下所示:
Email DateTimeCompleted
b@b.com 2019-01-29T01:34:44.591Z
2@2.com 2018-01-29T01:34:44.591Z
2@2.com 2019-02-09T01:34:44.591Z
我试过了:
from datetime import date
if df1.Email in df2.Email & df2.DateTimeCompleted >= date.today()-90 :
print('true')
我得到错误:
TypeError: 'Series' objects are mutable, thus they cannot be hashed
Also tried:
if df2.Email.str.contains(df1.Email.iat[0]):
print('true')
got error:
ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().
【问题讨论】:
标签: python-3.x pandas dataframe