python - 偏移现有日期值,其中值存在于数据框中的另一列中
问题描述
我正在尝试根据另一列(类型)中的值来抵消现有日期(在本例中为 2 个月)。
df.loc[df['Type'] == 'Lock', 'Start'] = df['Start'] + pd.DateOffset(months=-2)
Error: ValueError: cannot reindex from a duplicate axis
这可以像我尝试过的那样在一行中完成吗?如果没有,还有哪些其他方法?
解决方案
df['Start'] = np.where(df['Type'] == 'Lock',
df['Start'] + pd.DateOffset(months=-2),
df['Start'])
推荐阅读
- sql - 如何使用具有多列的 SQL 获取小计?
- openlayers - 在位置更新之间动画 GPS 点特征
- mysql - 如何从终端执行sql文件?
- mysql - SQL 查询。加入但在一个表中,每个元组有 2 次出现的连接属性
- ruby-on-rails - 更改分页器的 Kaminari url
- php - Laravel 队列数据未从构造函数传递到处理程序
- c# - 使用依赖注入测试 TypeFilterAttribute
- google-sheets - 如何使用 COUNTIF 定义多个工作表的范围?
- object - Vue V:模型动态创建对象
- javascript - 如何在 JavaScript 中创建一系列可以单击以执行相同功能的不同版本的按钮?