1

Trying to find the count of of business days in a range. So here's what I've got

df['ENTRYDATE'] = pd.to_datetime(df['ENTRYDATE'], errors='coerce')
df['REQDATE'] = pd.to_datetime(df['REQDATE'], errors='coerce')
df['DELDATE'] = pd.to_datetime(df['DELDATE'], errors='coerce')
df['SHIPCONFIRMED'] = pd.to_datetime(df['SHIPCONFIRMED'], errors='coerce')
#df['DAYSLATE'] = df['DELDATE'] - df['REQDATE']
req_date = df['REQDATE']
del_date = df['DELDATE']
df['DAYSLATE'] = df.ix[req_date:del_date].asfreq(BDay()).count()

But I'm getting a TypeError it looks like it's reading in the entire column instead of working with just the data in that row.

TypeError: '['2017-05-26T00:00:00.000000000' '2017-05-04T00:00:00.000000000' '2017-05-22T00:00:00.000000000' '2017-05-12T00:00:00.000000000' '2017-05-12T00:00:00.000000000' '2017-05-16T00:00:00.000000000' '2017-04-27T00:00:00.000000000' '2017-05-26T00:00:00.000000000' ... ... '2017-05-18T00:00:00.000000000' '2017-05-29T00:00:00.000000000' '2017-05-02T00:00:00.000000000' '2017-05-02T00:00:00.000000000' '2017-05-17T00:00:00.000000000' '2017-04-28T00:00:00.000000000']' is an invalid key

Any assistance or guidance is appreciated.

AlliDeacon
  • 1,365
  • 3
  • 21
  • 35
  • What are you asking exactly? you have `req_date = df['REQDATE']` so yes it's a column. Maybe you meant to do something like `df['DAYSLATE'] = df.DELDATE - df.REQDATE` and then count if value is positive? One way or the other it looks like you have mixed up columns and scalars (?) – JohnE Jun 29 '17 at 19:22
  • @JohnE I originally had `df['DAYSLATE'] = df.DELDATE - df.REQDATE` but that doesn't take business days into account. I am trying to count the business days between the Req Date and the Del Date. Thanks! also changing to `df.DELDATE` and `df.REQDATE` yielded the same error. – AlliDeacon Jun 29 '17 at 19:57
  • 1
    Oh, I see what you are trying to do: https://stackoverflow.com/questions/13019719/get-business-days-between-start-and-end-date-using-pandas You're trying to copy the first answer there but as I noted above, you're filling in with columns of dates rather than scalar (single values of) dates. I don't have time to work on this now, but the 2nd & 3rd answers there may be easier for you to implement with an apply. – JohnE Jun 29 '17 at 21:22

0 Answers0