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
77
votes
3 answers

Comparison between datetime and datetime64[ns] in pandas

I'm writing a program that checks an excel file and if today's date is in the excel file's date column, I parse it I'm using: cur_date = datetime.today() for today's date. I'm checking if today is in the column with: bool_val = cur_date in…
JesusMonroe
  • 1,421
  • 3
  • 13
  • 20
63
votes
10 answers

Extracting the first day of month of a datetime type column in pandas

I have the following dataframe: user_id purchase_date 1 2015-01-23 14:05:21 2 2015-02-05 05:07:30 3 2015-02-18 17:08:51 4 2015-03-21 17:07:30 5 2015-03-11 18:32:56 6 2015-03-03 11:02:30 and…
chessosapiens
  • 3,159
  • 10
  • 36
  • 58
28
votes
2 answers

numpy datetime64 add or substract date interval

I am parsing a huge ascii file with dates assigned to entries. So, I found myself using datetime package in parallel to numpy.datetime64 to add array capabilities. I know that the pandas package is probably most recommended to be used for date,…
Moe
  • 991
  • 2
  • 10
  • 24
15
votes
4 answers

Python/Pandas: How do I convert from datetime64[ns] to datetime

I have a script that processes an Excel file. The department that sends it has a system that generated it, and my script stopped working. I suddenly got the error Can only use .str accessor with string values, which use np.object_ dtype in pandas…
mattrweaver
  • 729
  • 4
  • 14
  • 36
15
votes
3 answers

How to force python print numpy datetime64 with specified timezone?

I want to see numpy datetime64 objects by my specified timezone. >>> import numpy as np >>> np.datetime64('2013-03-10T01:30:54') numpy.datetime64('2013-03-10T01:30:54+0400') >>>…
Samvel Hovsepyan
  • 639
  • 2
  • 6
  • 16
12
votes
3 answers

median of panda datetime64 column

Is there a way to compute and return in datetime format the median of a datetime column? I want to calculate the median of a column in python which is in datetime64[ns] format. Below is a sample to the column: df['date'].head() 0 2017-05-08…
T-Jay
  • 347
  • 1
  • 4
  • 16
6
votes
2 answers

Why is pd.Timestamp converted to np.datetime64 when calling '.values'?

When accessing the DataFrame.values, all pd.Timestamp objects are converted to np.datetime64 objects, why? An np.ndarray containing pd.Timestamp objects can exists, therefore I don't understand why would such automatic conversion always happen.…
Voy
  • 5,286
  • 1
  • 49
  • 59
6
votes
2 answers

Column arithmetic in pandas dataframe using dates

I think this should be easy but I'm hitting a bit of a wall. I have a dataset that was imported into a pandas dataframe from a Stata .dta file. Several of the columns contain date data. The dataframe contains 100,000+ rows but a sample is given: …
user1718097
  • 4,090
  • 11
  • 48
  • 63
5
votes
1 answer

numpy digitize with datetime64

I can't seem to get numpy.digitize to work with datetime64: date_bins = np.array([np.datetime64(datetime.datetime(2014, n, 1), 's') for n in range(1,13)]) np.digitize(date_bins, date_bins) It gives the following error: TypeError: Cannot cast array…
acrophobia
  • 924
  • 7
  • 22
4
votes
3 answers

How to add minutes to datetime64 object in a Pandas Dataframe

I want to add a list of minutes to datetime64 columns into a new df column. I tried using datetime.timedelta(minutes=x) in a for loop. But as a result, it is adding a constant value to all of my rows. How do I resolve this? for x in wait_min: …
Rick707
  • 63
  • 1
  • 5
4
votes
3 answers

Remove all rows between two timestamps from pandas dataframe

How to delete all rows from dataframe between two timestamps inclusive? my Dataframe looks like : b a 0 2016-12-02 22:00:00 19.218519 1 2016-12-02 23:00:00 19.171197 2 2016-12-03 00:00:00 19.257836 3 2016-12-03…
Nikita Gupta
  • 495
  • 9
  • 24
4
votes
1 answer

convert pandas dataframe column to np.datetime64

I want to add a np.datetime64 column to a pandas dataframe that has been read from a .csv file containing columns for year, month, day, hour and minute and use it as an index. I have combined the separate columns to make a column of datetime…
doctorer
  • 1,672
  • 5
  • 27
  • 50
4
votes
1 answer

How To Compare The Date From Two Numpy.datetime64

What is the proper method to compare the date portion of two numpy.datetime64's? A: 2011-01-10 Type: B: 2011-01-10T09:00:00.000000-0700 Type: The above example would return false by…
CamC
  • 89
  • 1
  • 6
4
votes
1 answer

Subclassing datetime64

How can I subclass from numpy datetime64 ? For instance using the standard datetime I can easily subclass: import datetime as dt class SubFromDateTime(dt.datetime): def __new__(cls): return dt.datetime.__new__(cls, 2012, 1, 1) print…
Muppet
  • 5,767
  • 6
  • 29
  • 39
1
2 3 4 5 6 7