Python Forum
Newbie Help with Datetime formats and numPy
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Newbie Help with Datetime formats and numPy
#3
See this SO post:

https://stackoverflow.com/questions/3191...with-numba

Essentially pandas store all datetimes in datetime64[ns] format only (i.e. down to nanoseconds), but busday_count requires datetimes in datetime64[D] format.

One option is to convert the dates to datetime64[D] format and store it as a numpy array. Something like:

import pandas as pd
import numpy as np

df = pd.read_csv('test11.csv', parse_dates = [1,2])
start_dates = np.array(df['Start_Date'].values.astype('datetime64[D]'))
complete_dates = np.array(df['Complete_Date'].values.astype('datetime64[D]'))
df['TAT'] = np.busday_count(start_dates, complete_dates)
print(df)
Output:
Title Start_Date Complete_Date TAT 0 projTitle 2020-01-19 2020-01-26 5 1 projTitle2 2020-02-11 2020-02-15 4
Reply


Messages In This Thread
RE: Newbie Help with Datetime formats and numPy - by palladium - Dec-31-2020, 03:00 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  [Numpy] How to store different data type in one numpy array? water 7 633 Mar-26-2024, 02:18 PM
Last Post: snippsat
  Numpy returns "TypeError: unsupported operand type(s) for *: 'numpy.ufunc' and 'int'" kalle 2 2,642 Jul-19-2022, 06:31 AM
Last Post: paul18fr
  "erlarge" a numpy-matrix to numpy-array PhysChem 2 3,008 Apr-09-2019, 04:54 PM
Last Post: PhysChem

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020