Questions tagged [datetimeindex]

Immutable ndarray of datetime64 data, represented internally as int64

Immutable ndarray of datetime64 data, represented internally as int64, and which can be boxed to Timestamp objects that are subclasses of datetime and carry metadata such as frequency information.

325 questions
5
votes
3 answers

Unable to slice pandas dataframe (with date as key) using date as string

I'm generating an empty dataframe with a series of dates as the index. Data will be added to the dataframe at a later point. cbd=pd.date_range(start=pd.datetime(2017,01,02),end=pd.datetime(2017,01,30),period=1) df =…
mpny1
  • 107
  • 2
  • 9
5
votes
2 answers

Split DateTimeIndex data based on hour/minute/second

I have time-series data that I would like to split based on hour, or minute, or second. This is generally user-defined. I would like to know how it can be done. For example, consider the following: test = pd.DataFrame({'TIME':…
Rohit
  • 5,840
  • 13
  • 42
  • 65
5
votes
4 answers

How to filter a pandas series with a datetime index on the quarter and year

I have a Series, called 'scores', with a datetime index. I wish to subset it by quarter and year pseudocode: series.loc['q2 of 2013'] Attempts so far: s.dt.quarter AttributeError: Can only use .dt accessor with datetimelike…
sapo_cosmico
  • 6,274
  • 12
  • 45
  • 58
5
votes
1 answer

Shift Pandas date index to next month

I have a dataframe with a date index. I want to create a new column with a lagged value. That is, laggedfoo(1aug2016) = foo(1july2016) I used dataframe.shift, but it didn't behave as expected; I can hack it to work, but I think I'm missing the…
user3556757
  • 3,469
  • 4
  • 30
  • 70
5
votes
1 answer

Fill datetimeindex gap by NaN

I have two dataframes which are datetimeindexed. One is missing a few of these datetimes (df1) while the other is complete (has regular timestamps without any gaps in this series) and is full of NaN's (df2). I'm trying to match the values from df1…
tg359x
  • 53
  • 1
  • 5
4
votes
3 answers

Pandas insert row into dataframe with timezone-aware index

I have a dataframe that has a timezone-aware index, and when I try to insert a new row into this dataframe, it doesn't work, instead changing the type of the index to 'object' (ie, it can't add in the row into the current type). MRE below: import…
Recessive
  • 1,780
  • 2
  • 14
  • 37
4
votes
2 answers

How can I generate a pandas date range with a frequency of Tue to Sat inclusive?

I am trying to generate a datetime index with pandas that has a custom daily frequency. At the moment, I can generate the following datetime index: import pandas as pd import datetime as…
agftrading
  • 784
  • 3
  • 8
  • 21
4
votes
0 answers

How to vectorize a pandas DateOffset?

I need to offset a DateTimeIndex index by a CustomBusinessDay, a trading day offset, which I instantiate like so: import pandas_market_calendars as mcal TCal = mcal.get_calendar('NYSE') from pandas.tseries.offsets import CustomBusinessDay TDay =…
4
votes
1 answer

DatetimeIndex stops DataFrame from returning from a decorated function

I have a decorator that adds the return of a function to a supplied dictionary or pandas data frame. This works fine as long as the data frame does not have different DateTimeIndex on the return. I tried simply merging the data frames and taking the…
crogg01
  • 2,446
  • 15
  • 35
4
votes
1 answer

How to get index of datetime within a pandas DateTimeIndex?

Is there a way to directly get the index of a certain datetime within a DateTimeIndex? I have following toy example code which does what I want after I convert the DateTimeIndex to a list. import pandas as pd import datetime year =…
Cedric Zoppolo
  • 4,271
  • 6
  • 29
  • 59
4
votes
2 answers

How to filter a pandas DatetimeIndex by day of week and hour in the day

I have a pandas DatetimeIndex and I would like to filter the index by the criterion that the day of the week and hour of the day matches a list. For example, I have of list of tuples indicating valid (day of week, hour, minute) for each…
motam79
  • 3,542
  • 5
  • 34
  • 60
4
votes
2 answers

How to filter a dataframe of dates and hours by a list of dates?

I have the following dataframe, with several days and a measure every 15minutes: CONSUMPTION 2016-11-01 01:00:00 3539 2016-11-01 01:15:00 3560 2016-11-01 01:30:00 3505 .... 2016-11-02 01:00:00 3400 2016-11-02 01:15:00 …
Izaskun
  • 173
  • 1
  • 8
4
votes
2 answers

Custom pandas Datetime offset / frequency for trading times: 9:30AM-4:00PM business days except US holidays

Trading data is recorded on non-holiday business days starting at 9:30AM, and data is recorded periodically (5 seconds, 5 minutes, 30 minutes, etc) until 4:00PM. For instance, [9:30AM, 9:35AM,...,3:50PM, 3:55PM] on non-holiday business days are…
4
votes
1 answer

Pandas: Cannot convert type to Timestamp

I got the following error message when trying to slicing a pandas dataframe using labels. triggerDate = dat.loc[dat.Close <= threshold[0]][:1].index cutDate= triggerDate.shift(1, 'd') dat.truncate(before=triggerDate, after=cutDate) TypeError:…
yuqli
  • 4,461
  • 8
  • 26
  • 46
4
votes
3 answers

python I want to set_index dataFrame with datetime

poorList = [datetime.date(2016, 5, 2), datetime.date(2016, 8, 26), datetime.date(2016, 6, 9), datetime.date(2016, 3, 4)] dateForm.set_index(poorList) then it was Error: File "pandas\index.pyx", line 137, in…
1
2
3
21 22