python - 使用 pandas groupby 检查预订日期和关闭日期的重叠
问题描述
overlap = df.groupby('CompanyName')
for g_idx, group in overlap:
for r_idx, row in group.iterrows():
if (row['ClosedDate'] - group['BookingDate'].any() > timedelta(0)):
df.loc[r_idx, 'overlap'] = True
else:
df.loc[r_idx, 'overlap'] = False
我收到此错误
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-111-52f6bd79e6d1> in <module>()
1 for g_idx, group in overlap:
2 for r_idx, row in group.iterrows():
----> 3 if (row['ClosedDate'] - group['BookingDate'].any() > timedelta(0)):
4 df.loc[r_idx, 'overlap'] = True
5 else:
3 frames
/usr/local/lib/python3.7/dist-packages/pandas/core/arrays/base.py in _reduce(self, name, skipna, **kwargs)
1145 TypeError : subclass does not define reductions
1146 """
-> 1147 raise TypeError(f"cannot perform {name} with type {self.dtype}")
1148
1149 def __hash__(self):
TypeError: cannot perform any with type datetime64[ns, UTC]
解决方案
推荐阅读
- firebase - 跟踪通过 Google Cloud Functions 传播的请求
- pandas - 通过子类别均值加速 Pandas fillna(如何替换 for 循环)
- rxjs - RxJS 6.5.5 startWith 已弃用。选择
- angular - KeyboardEvent Typescript 不正确的键初始化
- web-scraping - 从画廊网站收集描述的基本刮板
- powershell - 我怎样才能在只获得我需要的信息的情况下转换它?
- jenkins - 配置詹金斯作业时看不到构建步骤
- pyspark - 无法使用 Pyspark 中的更新将字符串插入增量表
- excel-formula - 使用工作表编号而不是名称链接单元格
- vba - 将文件转换为二进制并发送到 API