简体   繁体   English

列出两个数据框列之间的工作日

[英]Listing business days between two dataframe columns

Rather than counting, I need the actual list of business days between begin and end date columns in my dataframe so I can loop through them to add rows for another issue.我不需要计算,而是需要数据框中开始日期列和结束日期列之间的实际工作日列表,以便我可以遍历它们为另一个问题添加行。

Here's what I'm looking for (created the 'list bd' column manually to show what I would like the output to be):这是我正在寻找的内容(手动创建“list bd”列以显示我想要的输出):

 begin date end date    list bd
2020-11-02  2020-11-04  ['2020-11-02', '2020-11-03', '2020-11-04']
2020-11-03  2020-11-06  ['2020-11-03', '2020-11-04', '2020-11-05', '2020-11-06']
2020-11-05  2020-11-10  ['2020-11-05', '2020-11-06', '2020-11-09', '2020-11-10']

What I've tried:我试过的:

df['list_bd'] = pd.bdate_range(df['begin date'], df['end date']).tolist()

You can simply zip the columns begin date and end date and use bdate_range inside a list comprehension:您可以简单地zip列的begin dateend date并在列表理解中使用bdate_range

df['list bd'] = [pd.bdate_range(*v).astype(str).tolist() for v in zip(df['begin date'], df['end date'])]

  begin date   end date                                           list bd
0 2020-11-02 2020-11-04              [2020-11-02, 2020-11-03, 2020-11-04]
1 2020-11-03 2020-11-06  [2020-11-03, 2020-11-04, 2020-11-05, 2020-11-06]
2 2020-11-05 2020-11-10  [2020-11-05, 2020-11-06, 2020-11-09, 2020-11-10]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM