比较熊猫中的两个列与数据框中的更新日期列
我需要将列的一定范围与另一列中的特定字符串进行比较,以用1,7、30天更新日期列,
Col A ColB colc
5 Internal 1-1-2022
7 external 1-1-2022
4 external 1-1-2022
3 external 1-1-2022
因此,如果df [cola]< 8
和df [colb] =外部
向DF [Colc]添加7天。如果df [cola]> = 8
and df [colb] =外部
将30天添加到df [colc],以及df [colb] =内部
将120天添加到DF [COLC]
I need to compare a certain range of value of a column with a specific string in another column to update the date column with 1,7, 30 days
Col A ColB colc
5 Internal 1-1-2022
7 external 1-1-2022
4 external 1-1-2022
3 external 1-1-2022
so if df[ColA]<8
and df[ColB]=External
add 7 days to df[colc]. if if df[ColA]>=8
and df[ColB]=External
add 30 days to df[colc] and if df[ColB]=Internal
add 120 days to df[Colc]
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以使用
处理所有条件:numpy.select.select
我将它们简化为:
输出:
You can use
numpy.select
to handle all your conditions:I simplified them to:
output:
使用相同的
np.Select
与@mozway,我建议使用pd.timedelta
。结果:
Using the same
np.select
as @mozway, I would suggest usingpd.Timedelta
.Result: