Questions tagged [datetime64]

NumPy array datatype with native support for datetime functionality

Since NumPy 1.7.0, the dtypes datetime64 and timedelta64 provide support for array types for datetime and timedelta functionality, respectively. Use this tag for questions specifically relating to these dtypes.

For more information, refer to the NumPy manual.

101 questions
2
votes
1 answer

What's the fastest way to compare datetime in pandas?

I have two big csv files with different number of rows which I am importing as follows: tdata = pd.read_csv(tfilepath, sep=',', parse_dates=['date_1']) print(tdata.iloc[:, [0,3]]) TBA date_1 0 0 2010-01-04 1 9 2010-01-05 2…
Floydian
  • 380
  • 1
  • 14
2
votes
1 answer

How to create of Numpy array of datetime64 objects using C API?

I need to create an array of numpy datetime64 objects from C/C++ code. As you can see for NPY_LONGLONG and NPY_VOID I did it. I need to do the same thing for NPY_DATETIME type. PyObject *arr1 = PyArray_SimpleNew(1, &dims, NPY_LONGLONG); PyObject…
Samvel Hovsepyan
  • 639
  • 2
  • 6
  • 16
1
vote
1 answer

Pandas DataFrame with dates far in the future

I need to store some dates which are beyond the year-2262-limit. Since I only need dates and no times I thought I could get away with using datetime.date, which did work fine until I realised that later in the code there is some forced coercion of…
mcenno
  • 509
  • 5
  • 18
1
vote
2 answers

Issue with converting a pandas column from int64 to datetime64

I'm trying to convert a column of Year values from int64 to datetime64 in pandas. The column currently looks like Year 2003 2003 2003 2003 2003 ... 2021 2021 …
EcoHealthGuy
  • 51
  • 1
  • 1
  • 7
1
vote
2 answers

Getting full seconds and microseconds from Numpy datetime64

I need to get a timedelta as a full float of seconds and microseconds, for instance 2.786 seconds. Doing this with datetime64's specifying 'ms' as milliseconds elapsed_time = np.datetime64(dial_1, 'ms') - np.datetime64(dial_2, 'ms') Gives me…
1
vote
0 answers

Get the date of last day of next month based on a given date

I have a pandas dataframe with a column consisting of dates and the type of the column is datetime64[ns]. I'm trying to get the date of the last day of next month. For example, I have 2020-11-30 and my code is returning 2020-12-30, but I would like…
PKV
  • 167
  • 3
  • 13
1
vote
1 answer

Why does my date column change when I convert to an ndarray

below is my dataframe from pandas import Timestamp df = pd.DataFrame({'Year': [Timestamp('2023-03-14 00:00:00'),Timestamp('2063-03-15 00:00:00'),Timestamp('2043-03-21 00:00:00'),Timestamp('2053-10-09 00:00:00')], 'offset' : [1,…
user13412850
  • 509
  • 1
  • 5
  • 16
1
vote
1 answer

How to add a month using np.datetime64 and np.timedelta64

I'm trying to add a month to a np.datetime64: np.datetime64('2020-01-05') + np.timedelta64(1, "M") but this error raises: Cannot cast ufunc 'subtract' input 1 from dtype('
AsiaLootus
  • 112
  • 1
  • 10
1
vote
0 answers

Specifying datetime64 resolution in Ibis when converting to Pandas DataFrame

I have a MySQL database with datetime values shifted by arbitrary amounts for de-identification purposes. So, for example, I have a date value of datetime.datetime(2644, 1, 17, 0, 0) . If I query these values with pymysql or Pandas I get a fine…
1
vote
1 answer

How do I generate a datetime64[ns, UTC] numpy series?

I am trying to generate a numpy series of type datetime64[ns, UTC] without success. This is what I have tried: test = np.array(np.datetime64('2005-01-03 14:30:00.000000000')) test >array('2005-01-03T14:30:00.000000000', dtype='datetime64[ns]') And…
M.E.
  • 4,955
  • 4
  • 49
  • 128
1
vote
1 answer

Convert timezone of a pandas column datetime64 from UTC to America/New_York

I have tried the following to change timezone Pandas dataframe: print(df['column_datetime'].dtypes) print(df['column_datetime'].tz_localize('America/New_York').dtypes) print(df['column_datetime'].tz_convert('America/New_York').dtypes) Which gives…
M.E.
  • 4,955
  • 4
  • 49
  • 128
1
vote
1 answer

Trying to find the nearest date before and after a specified date from a list of dates in a comma separated string within a pandas Dataframe

tldr; I have an index_date in dtype: datetime64[ns] and a list_of_dates of type with individual elements in str format. What's the best way to convert these to the same data type so I can sort the…
anbk
  • 63
  • 1
  • 7
1
vote
0 answers

Get a single datetime feature (such as day, hour, year) from a Numpy.datetime64 array

I am currently updating an script, which was written using datetime library from datetime import datetime and timedelta One of the cool features of datetime is the function that returns you a datetime feature (suchs as .day, .year, .hour).…
joueswant
  • 136
  • 10
1
vote
1 answer

Pandas dataframe plot(): x-axis date labels display but not data

I am trying to plot data as a function of time (years) from a pandas data frame. A summary of the data is shown here: DATE WALCL 0 2010-08-18 2313662 1 2010-08-25 2301015 2 2010-09-01 2301996 3 2010-09-08 2305802 4 …
reg
  • 23
  • 4
1
vote
2 answers

How to Convert a List to numpy.datetime64 format

I know that we can create a single string to np.datetime64 format such as: a = np.datetime64('2020-01-01') But what if we have a list with multiple strings of dates in it? How are we able to apply the same np.datetime64 to convert all the elements…
funkymickey
  • 111
  • 3
  • 8