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
4
votes
1 answer

Pandas, dataframe with a datetime64 column, querying by hour

I have a pandas dataframe df which has one column constituted by datetime64, e.g. Int64Index: 1471 entries, 0 to 2940 Data columns (total 2 columns): date 1471 non-null values id 1471 non-null…
Acorbe
  • 8,367
  • 5
  • 37
  • 66
4
votes
2 answers

How does one determine the time unit in numpy.datetime64?

I can't see how to reveal the units for numpy.datetime64. Say: t=np.datetime64(123456789, 'ms' ) What's the method to tell me the units are 'ms'?
Quant
  • 4,253
  • 3
  • 17
  • 15
4
votes
2 answers

Motivation behind numpy's datetime64 type?

I noticed recently that numpy includes a datetime64 data type beginning in numpy 1.7: http://www.compsci.wm.edu/SciClone/documentation/software/math/NumPy/html1.7/reference/arrays.datetime.html I am wondering what is the motivation behind including…
Setjmp
  • 27,279
  • 27
  • 74
  • 92
3
votes
1 answer

Future Warning: Passing datetime64-dtype data to TimedeltaIndex is deprecated

I have a dataset of measured values and their corresponding timestamps in the format hh:mm:ss, where hh can be > 24 h. For machine learning tasks, the data need to be interpolated since there are multiple measured values with different timestamps,…
Max K.
  • 51
  • 1
  • 8
3
votes
1 answer

How to keep dtype when converting a dataframe into a numpy array?

I have a dataframe and want to convert it into a numpy array to plot its values. The dataframe looks like this: >>> df_ohlc open high low close Date …
maynull
  • 1,936
  • 4
  • 26
  • 46
3
votes
1 answer

Creating tz aware pandas timestamp objects from an integer

I have a integer that is the number of microseconds after the unix epoch. (in GMT) How can I convert 1349863207154117 using astype to a pandas.Timestamp("2012-10-10T06:00:07.154117", tz=¨UTC¨)? The documentation on astype is not very thorough. I…
Michael WS
  • 2,450
  • 4
  • 24
  • 46
3
votes
1 answer

How to convert pandas timezone aware timestamps to UNIX epoche?

I need to convert a timezone aware date_range (TimeStamps) to UNIX epoch values for use in an external Javascript library. My approach is: # Create localized test data for one day rng = pd.date_range('1.1.2014', freq='H', periods=24,…
THM
  • 745
  • 2
  • 8
  • 14
3
votes
1 answer

Casting datetime64 to different time unit

Suppose T is numpy.datetime64 in units of ms. Is there a less obscure way to convert the units than this? T1 = np.array( [T], dtype = 'datetime64[ns]' )[0] I'm prefer something more guessable, and, for that matter, readable.
Quant
  • 4,253
  • 3
  • 17
  • 15
2
votes
1 answer

How to groupby and plot aggregated data?

I have a column in my dataframe with dates of users logging in, it's formatted as follows: 0 2020-09-24 23:37:13+02:00 1 2020-09-24 22:08:02+02:00 2 2020-09-24 21:40:01+02:00 3 2020-09-24 21:16:22+02:00 4 2020-09-24…
Rysicin
  • 95
  • 1
  • 10
2
votes
1 answer

Extract Year, Month and Day from datetime64[ns, UTC], Python

I have this column in a df: > df["time"] 0 2007-02-01 22:00:00+00:00 1 2007-02-01 22:00:00+00:00 2 2007-02-01 22:00:00+00:00 3 2007-02-01 22:00:00+00:00 4 2007-02-01 22:00:00+00:00 I want to create three…
Chris
  • 2,019
  • 5
  • 22
  • 67
2
votes
2 answers

Get next available date in Pandas filter by day

I have filtered the datetime64[ns] type in pandas dataframe to get data that falls on specific date of each month using the following line of code. df[df['Date'].map(lambda x: x.day) == 1] The output is as follows: 19.9 2013-07-01 34.8 …
navule
  • 3,212
  • 2
  • 36
  • 54
2
votes
1 answer

Filter outliers in DataFrame rows based on a recursive time-interval

I have the following DataFrame df: ds y 2018-10-01 00:00 1.23 2018-10-01 01:00 2.21 2018-10-01 02:00 6.40 ... ... 2018-10-02 00:00 3.21 2018-10-02 01:00 3.42 2018-10-03 02:00 2.99 ... …
espogian
  • 607
  • 8
  • 23
2
votes
2 answers

Loop over 24-hour period using list of dates in Python

I have a list of np.datetime64 dates in Python: ['2016-12-01T02:00:00.000000000', '2016-12-01T04:00:00.000000000', '2016-12-01T06:00:00.000000000', '2016-12-01T08:00:00.000000000', '2016-12-01T10:00:00.000000000', '2016-12-01T12:00:00.000000000',…
tda
  • 2,045
  • 1
  • 17
  • 42
2
votes
2 answers

How can I separate np.datetime64 information into different columns?

I'm trying to create a date array whose colums are: day, month and year between two specific dates (time delta = 1 day). I know this must be very simple to do, but I couldn't find a similar example. I've found that I can create date arrays using…
lanadaquenada
  • 395
  • 3
  • 4
  • 26
2
votes
1 answer

pandas to_csv and then read_csv results to numpy.datetime64 messed up due to utc

Here is my problem in short: I am trying to write my data (containing, among other, np.datetime64 values) to csv and then read them back, and want my times not to change... As discussed in many places, np.datetime64 keeps everything binary and UTC…
ntg
  • 12,950
  • 7
  • 74
  • 95