计算没有星期六的下一次约会



我想计算卡车在周六(但不是周日(静止的交货日期如果交货期是两天,而我在周五订购,那么货物应该在周一(周日+周一(到达。以下内容很好,但不包括周日:

df['LEV'] = dat + df['Leadtime'].map(pd.tseries.offsets.BusinessDay)

我想做这样的事。但它不起作用:

df['LEV'] = dat + df['Leadtime'].map(pd.tseries.offsets.CustomBusinessDay(weekmask = 'Mon Tue Wed Thu Fri Sun'))

其中:

2021-05-14 00:00:00
<class 'datetime.datetime'>
<class 'pandas.core.series.Series'>

谢谢

编辑:小示例:

from datetime import datetime
DatToday = datetime.fromisoformat('2022-01-13')
data = {'Article': ['A1', 'A2'], 'LeadTime': [2, 6], 'DateToday': 
[DatToday,DatToday]}    
df = pd.DataFrame(data)  

df['Delivery_Day'] = DatToday + df['LeadTime'].map(pd.tseries.offsets.BusinessDay)

当前结果:

Article    LeadTime  DateToday     Delivery_Day
0     A1    2        2022-01-13    2022-01-17
1     A2    6        2022-01-13    2022-01-21

想要的结果:

Article    LeadTime  DateToday     Delivery_Day
0     A1    2        2022-01-13    2022-01-16
1     A2    6        2022-01-13    2022-01-20

也就是说,没有星期天的商业日。

错误消息:

~Anaconda3libsite-packagespandascoreseries.py in apply(self, func, 
convert_dtype, args, **kwds)
4198             else:
4199                 values = self.astype(object)._values
-> 4200                 mapped = lib.map_infer(values, f, 
convert=convert_dtype)
4201 
4202         if len(mapped) and isinstance(mapped[0], Series):
pandas_libslib.pyx in pandas._libs.lib.map_infer()
pandas_libstslibsoffsets.pyx in 
pandas._libs.tslibs.offsets.BaseOffset.__call__()
pandas_libstslibsoffsets.pyx in 
pandas._libs.tslibs.offsets.apply_wraps.wrapper()
ApplyTypeError: 

您需要将您的CustomBusinessDay乘以天数:

cbd = pd.tseries.offsets.CustomBusinessDay(weekmask='Mon Tue Wed Thu Fri Sun')
df['Delivery_Day'] = DatToday + df['LeadTime'] * cbd

输出:

Article  LeadTime  DateToday Delivery_Day
0      A1         2 2022-01-13   2022-01-16
1      A2         6 2022-01-13   2022-01-20

相关内容

  • 没有找到相关文章

最新更新