datetime64

Replace a single character in a Numpy list of strings

孤人 提交于 2021-01-28 11:20:55
问题 I have a Numpy array of datetime64 objects that I need to convert to a specific time format yyyy-mm-dd,HH:MM:SS.SSS Numpy has a function called datetime_as_string that outputs ISO8601 (yyyy-mm-ddTHH:MM:SS.SSS) time, which is extremely close to what I want, the only difference being there is a T where I want a comma. Is there a way to quickly swap the "T" for a ","? Here is an example data set: offset = np.arange(0, 1000) epoch = np.datetime64('1970-01-01T00:00:00.000') time_objects = epoch +

How do I convert numpy array to days, hours, mins?

a 夏天 提交于 2020-12-13 03:12:36
问题 Running with this series X = number_of_logons_all.values split = round(len(X) / 2) X1, X2 = X[0:split], X[split:] mean1, mean2 = X1.mean(), X2.mean() var1, var2 = X1.var(), X2.var() print('mean1=%f, mean2=%f' % (mean1, mean2)) print('variance1=%f, variance2=%f' % (var1, var2)) I get: mean1=60785.792548, mean2=61291.266868 variance1=7483553053.651829, variance2=7603208729.348722 But I wanted something like this in my PyCharm console (pulled from another result): >>> -103 days +04:37:13

How do I convert numpy array to days, hours, mins?

戏子无情 提交于 2020-12-13 03:10:19
问题 Running with this series X = number_of_logons_all.values split = round(len(X) / 2) X1, X2 = X[0:split], X[split:] mean1, mean2 = X1.mean(), X2.mean() var1, var2 = X1.var(), X2.var() print('mean1=%f, mean2=%f' % (mean1, mean2)) print('variance1=%f, variance2=%f' % (var1, var2)) I get: mean1=60785.792548, mean2=61291.266868 variance1=7483553053.651829, variance2=7603208729.348722 But I wanted something like this in my PyCharm console (pulled from another result): >>> -103 days +04:37:13

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

£可爱£侵袭症+ 提交于 2020-01-05 06:46:29
问题 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 *arr2 = PyArray_New(&PyArray_Type, 1, &dims, NPY_VOID, NULL, NULL, item_size, 0, NULL); The problem is that there is no documentation about what is the internal representation of NPY_DATETIME type, so I don't know if it has an fixed size, structure or

median of panda datetime64 column

∥☆過路亽.° 提交于 2019-12-30 09:30:08
问题 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 13:25:13.342 1 2017-05-08 16:37:45.545 2 2017-01-12 11:08:04.021 3 2016-12-01 09:06:29.912 4 2016-06-08 03:16:40.422 Name: recency, dtype: datetime64[ns] My aim is to have the median in same datetime format as the date column above: Tried converting to np

datetime64 comparison in dataframes

假装没事ソ 提交于 2019-12-13 08:09:20
问题 I am struggling with datetime64 comparisons in dataframes to update a column. lets say we have a dataframe 'df' with a 'date' column df.date.values[0] Out[128]: numpy.datetime64('2015-05-17T22:00:00.000000000+0800') i needed to drop the time and just do a date comparison, so to extract the date i use .date() df.date[0].date() Out[131]: datetime.date(2015, 5, 17) I test it out first df.date[0].date()==np.datetime64('2015-05-17') Out[132]: True So all seems good i try to do a condition if date

Column arithmetic in pandas dataframe using dates

北战南征 提交于 2019-12-12 10:46:52
问题 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: cat event_date total 0 G2 2006-03-08 16 1 G2 NaT NaN 2 G2 NaT NaN 3 G3 2006-03-10 16 4 G3 2006-08-04 12 5 G3 2006-12-28 13 6 G3 2007-05-25 10 7 G4 2006-03-10 13 8 G4 2006-08-06 19 9 G4 2006-12-30 16 The data is stored as a datetime64 format: >>>

numpy datetime64 add or substract date interval

一世执手 提交于 2019-12-12 09:35:08
问题 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, however try to pull this off without pandas. I have been looking around for a neat way to add/subtract a certain datestep like one year, or 3 month from a datetime64 object. Currently, I am converting dt64 object to dt object and use replace function

How to force python print numpy datetime64 with specified timezone?

佐手、 提交于 2019-12-09 15:28:28
问题 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') >>> np.datetime64('2013-03-10T01:30:54+0300') numpy.datetime64('2013-03-10T02:30:54+0400') Python prints datetime objects always in UTC+0400 (it is my local timezone) even if I specify another timezone >>> np.datetime64('2013-03-10T01:30:54+0300') . Is there a way to force python print by UTC+0000 timezone? I am using

Pandas, dataframe with a datetime64 column, querying by hour

若如初见. 提交于 2019-12-06 12:10:51
问题 I have a pandas dataframe df which has one column constituted by datetime64 , e.g. <class 'pandas.core.frame.DataFrame'> Int64Index: 1471 entries, 0 to 2940 Data columns (total 2 columns): date 1471 non-null values id 1471 non-null values dtypes: datetime64[ns](1), int64(1) I would like to sub-sample df using as criterion the hour of the day (independently on the other information in date ). E.g., in pseudo code df_sub = df[ (HOUR(df.date) > 8) & (HOUR(df.date) < 20) ] for some function HOUR