datetimeindex

extend a pandas datetimeindex by 1 period

百般思念 提交于 2020-05-28 14:53:14
问题 consider the DateTimeIndex dates dates = pd.date_range('2016-01-29', periods=4, freq='BM') dates DatetimeIndex(['2016-01-29', '2016-02-29', '2016-03-31', '2016-04-29'], dtype='datetime64[ns]', freq='BM') I want to extend the index by one period at the frequency attached to the object. I expect pd.date_range('2016-01-29', periods=5, freq='BM') DatetimeIndex(['2016-01-29', '2016-02-29', '2016-03-31', '2016-04-29', '2016-05-31'], dtype='datetime64[ns]', freq='BM') I've tried dates.append(dates[[

Pandas Timestamp rounds 30 seconds inconsistently

删除回忆录丶 提交于 2020-05-09 04:03:06
问题 I'm trying to round a pandas DatetimeIndex (or Timestamp) to the nearest minute, but I'm having a problem with Timestamps of 30 seconds - some rounding up, some rounding down (this seems to alternate). Any suggestions to fix this so that 30s always rounds up? >>> pd.Timestamp(2019,6,1,6,57,30).round('1T') Timestamp('2019-06-01 06:58:00') >>> pd.Timestamp(2019,6,1,6,58,30).round('1T') Timestamp('2019-06-01 06:58:00') The top result looks fine, with 57m 30s rounding up to 58m, but I'd expect

select dataframe rows (datetimeindex) by a list of datetime.date

做~自己de王妃 提交于 2020-01-15 09:15:49
问题 the df looks like this: DateTime 2017-07-10 03:00:00 288.0 2017-07-10 04:00:00 306.0 2017-08-10 05:00:00 393.0 2017-08-10 06:00:00 522.0 2017-09-10 07:00:00 487.0 2017-09-10 08:00:00 523.0 2017-10-10 09:00:00 585.0 Question how to select row that in a list of dates: ['2017-07-10', '2017-09-10'] to have: DateTime 2017-07-10 03:00:00 288.0 2017-07-10 04:00:00 306.0 2017-09-10 07:00:00 487.0 2017-09-10 08:00:00 523.0 Thanks 回答1: Assuming the Datetime is index, try with the below: to_search=[

Adding offset to timestamp in pandas

和自甴很熟 提交于 2019-12-24 06:14:40
问题 I have a dataframe df and when I run print(df.index), I get: DatetimeIndex(['2011-08-05 00:00:00-04:00', '2011-08-05 01:00:00-04:00', '2011-08-05 02:00:00-04:00', '2011-08-05 03:00:00-04:00', '2011-08-05 04:00:00-04:00', '2011-08-05 05:00:00-04:00', '2011-08-05 06:00:00-04:00', '2011-08-05 07:00:00-04:00', '2011-08-05 08:00:00-04:00', '2011-08-05 09:00:00-04:00', ... '2017-07-30 14:00:00-04:00', '2017-07-30 15:00:00-04:00', '2017-07-30 16:00:00-04:00', '2017-07-30 17:00:00-04:00', '2017-07-30

PANDAS - Loop over two datetime indexes with different sizes to compare days and values

筅森魡賤 提交于 2019-12-24 03:23:47
问题 Looking for a more efficient way to loop over and compare datetimeindex values in two Series objects with different frequencies. Setup Imagine two Pandas series, each with a datetime index covering the same year span yet with different frequencies for each index. One has a frequency of days, the other a frequency of hours. range1 = pd.date_range('2016-01-01','2016-12-31', freq='D') range2 = pd.date_range('2016-01-01','2016-12-31', freq='H') I'm trying to loop over these series using their

Pandas: Accessing data with list of dates and DateTimeIndex

我的未来我决定 提交于 2019-12-22 06:27:16
问题 I have a pandas DataFrame with a DateTimeIndex : A B 2016-04-25 18:50:06 440.967796 201.049600 2016-04-25 18:50:13 441.054995 200.767034 2016-04-25 18:50:20 441.142337 200.484475 ... 2016-07-27 18:50:06 440.967796 201.049600 2016-07-27 18:50:13 441.054995 200.767034 2016-07-27 18:50:20 441.142337 200.484475 I would like to extract all the data of a given date yyyy-mm-dd using a list of dates: ['2016-04-25','2016-04-28',...] I tried the following: df[df.index.isin(['2016-04-25', '2016-04-26'])

time slice on second level of multiindex

南笙酒味 提交于 2019-12-21 17:03:10
问题 pandas allows for cool slicing on time indexes. For example, I can slice a dataframe df for the months from Janurary 2012 to March 2012 by doing: df['2012-01':'2012-03'] However, I have a dataframe df with a multiindex where the time index is the second level. It looks like: A B C D E a 2001-01-31 0.864841 0.789273 0.370031 0.448256 0.178515 2001-02-28 0.991861 0.079215 0.900788 0.666178 0.693887 2001-03-31 0.016674 0.855109 0.984115 0.436574 0.480339 2001-04-30 0.120924 0.046013 0.659807 0

Pandas DatetimeIndex indexing dtype: datetime64 vs Timestamp

我的未来我决定 提交于 2019-12-12 20:07:51
问题 Indexing a pandas DatetimeIndex (with dtype numpy datetime64[ns]) returns either: another DatetimeIndex for multiple indices a pandas Timestamp for single index The confusing part is that Timestamps do not equal np.datetime64, so that: import numpy as np import pandas as pd a_datetimeindex = pd.date_range('1/1/2016', '1/2/2016', freq = 'D') print np.in1d(a_datetimeindex[0], a_datetimeindex) Returns false. But: print np.in1d(a_datetimeindex[0:1], a_datetimeindex) print np.in1d(np.datetime64(a

TypeError: cannot concatenate a non-NDFrame object

江枫思渺然 提交于 2019-12-12 12:57:25
问题 I have this DatetimeIndex: dates = DatetimeIndex(['2017-06-09', '2017-06-10', '2017-06-11', '2017-06-12', '2017-06-13', '2017-06-14'], dtype='datetime64[ns]', freq='<DateOffset>') I want to take dates and append them to my DataFrame df : for i in xrange(0,5): df.append(dates[i],ignore_index=True) I get this error TypeError: cannot concatenate a non-NDFrame object . UPDATE: sample data of df : Out[85]: 2017-06-05 -0.944868 2017-06-06 0.073623 2017-06-07 -0.687232 Freq: <DateOffset>, dtype:

pandas.DatetimeIndex.snap timestamps to left occurring frequency

天涯浪子 提交于 2019-12-12 12:32:09
问题 I would like to have the same functionality that snap but using the left occurring frequency instead of the nearest. This is what I am trying: date = pd.date_range('2015-01-01', '2015-12-31') week_index = pd.DatetimeIndex.snap(date, 'W-MON') week_index DatetimeIndex(['2014-12-29', '2015-01-05', '2015-01-05', '2015-01-05', '2015-01-05', '2015-01-05', '2015-01-05', '2015-01-05', '2015-01-12', '2015-01-12', ... '2015-12-21', '2015-12-21', '2015-12-21', '2015-12-28', '2015-12-28', '2015-12-28',