0

I want to calculate business days with np.busday_count but some rows have start date and some rows don't have

enter image description here

import numpy as np
import pandas as pd

dfProd = pd.read_csv('fgc.csv', low_memory=False)


def business_days(start, end):
    mask = pd.notnull(start) & pd.notnull(end)
    start = start.values.astype('datetime64[D]')[mask]
    end = end.values.astype('datetime64[D]')[mask]
    result = np.empty(len(mask), dtype=float)
    result[mask] = np.busday_count(start, end)
    result[~mask] = np.nan
    return result


dfProd['prod'] = business_days(dfProd['Start'], dfProd['End'])
print(dfProd)

but I got this error

ValueError: Could not convert object to NumPy datetime

I added prod where I will add Business Days

How I can skip Null rows but not drop them?

radojicic
  • 27
  • 5
  • Does this answer your question? [Counting the business days between two series](https://stackoverflow.com/questions/17703436/counting-the-business-days-between-two-series) – MattR May 20 '20 at 18:55
  • MattR, no because there are all dated and tere are not NULL in date column – radojicic May 20 '20 at 20:32
  • [MRE guide](https://stackoverflow.com/questions/20109391/how-to-make-good-reproducible-pandas-examples) – sammywemmy May 20 '20 at 22:38

0 Answers0