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
1
vote
0 answers

Create custom index with only minutes/seconds/deciseconds in dataframe

I am working on a heart rate time series available here. Per dataset description, the series "contains 1800 evenly-spaced measurements of instantaneous heart rate from a single subject [...] The measurements (in units of beats per minute) occur at…
1
vote
1 answer

Interpolate only short gaps in pandas dataframe with DateTimeIndex

I am looking fopr a way to interpolate only over short gaps in a Pandas DataFrame that has a DateTimeIndex. Long gaps should be kept as they are. df = pd.DataFrame( { "value": [ 1, np.nan, 3, np.nan, np.nan, 5, np.nan, 11, np.nan, 21, np.nan, 41…
leviathan
  • 363
  • 3
  • 10
1
vote
1 answer

Python - Pandas resample dataframe with strings and floats

I have a dataframe where the index is a datetimeindex, and every row is every day over the course of a couple years. I need to resample the dataframe by month where the two float columns are summed, but the string columns are all the unique values…
Chris Macaluso
  • 1,372
  • 2
  • 14
  • 33
1
vote
1 answer

Pandas datetimeindex intersection with more than two indexes

Is it possible to use a groupby operation with Pandas datetimeindex? When grouping the index below, I would like to return the date intersection for each of the groupby objects. I know there is pandas.DatetimeIndex.intersection - however this…
mrk.jhsn
  • 13
  • 5
1
vote
2 answers

Pandas SetIndex with DatetimeIndex

I have a csv file with the following Symbol, Date, Unix_Tick, OpenPrice, HighPrice, LowPrice, ClosePrice, volume, AAPL, 2021-01-04 09:00:00, 1609750800, 133.31, 133.49, 133.02, 133.49, 25000 AAPL, 2021-01-04 09:01:00, 1609750860, 133.49, 133.49,…
Jason
  • 81
  • 6
1
vote
0 answers

Faster pandas DatetimeIndex membership checking

I have a tight loop which, among other things, checks whether a given date (in the form of a pandas.Timestamp) is contained in a given unique pandas.DatetimeIndex (the application being checking whether a date is a custom business day). As a minimal…
NinjaTuna
  • 41
  • 5
1
vote
2 answers

Got DatetimeIndex. Now how do I get these records to excel?

Goal: From an excel file, I want to get all the records which have dates that fall within a range and write them to a new excel file. The infile I'm working with has 500K+ rows and 21 columns. What I've tried: I've read the infile to a Pandas…
Pfalbaum
  • 586
  • 3
  • 10
  • 26
1
vote
2 answers

Find gaps between pandas dateranges that overlap

I'm trying to find the gaps where a set of dateranges don't overlap a larger daterange. In the below example I'd like to find each gap where daterange_1 to daterange_3 don't overlap big_daterange. At the moment I've gotten this far, but I'm stuck in…
oxidising
  • 171
  • 2
  • 16
1
vote
1 answer

How to create a time matrix full of NaT in python?

I would like to create an empty 3D time matrix (with known size) that I will later populate in a loop with either pd.dateTimeIndex or a list of pd.timestamp. Is there a simple method ? This does not work: timeMatrix = np.empty( shape=(100, 1000, 2)…
PierreL
  • 169
  • 9
1
vote
1 answer

Whats is the most common way to convert a Timestamp to an int

I tried multiple ways but they always give me an error. The most common error I get is : AttributeError: 'Timestamp' object has no attribute 'astype' Here is the line where I try to convert my element : df.index.map(lambda x: x - oneSec if…
TheHaricover
  • 47
  • 1
  • 6
1
vote
1 answer

DatetimeIndex to integer by hours

I have a dataframe that I grouped with function groupby. In order to do so, I had to use DatetimeIndex. However, I would like to transform my datetimeindex as integer to use it as index for aa dynamic optimization model. I'm able to transform my…
Philippe
  • 31
  • 4
1
vote
1 answer

Pandas: calculating average behaviour of time series data around an event

I have two dataframes with date time information, df_stream is a stream of events and df_events are specific events in time. For example: The blue is the stream and the red line is the event. The window is 30min either side of the event and the…
philMarius
  • 470
  • 5
  • 19
1
vote
1 answer

Slicing pandas dataframe via index datetime

I tried to slice a pandas dataframe, that was read from the CSV file and the index was set from the first column of dates. IN: df = pd.read_csv(r'E:\...\^d.csv') df["Date"] = pd.to_datetime(df["Date"]) OUT: Date Open High Low Close …
AlexStox
  • 61
  • 9
1
vote
2 answers

Why does adding CDay() to DatetimeIndex include a weekend?

I am on pandas version 1.1.3. Suppose I have the following index import pandas as pd from pandas.tseries.offsets import CDay idx = pd.bdate_range("2010-02-03","2010-02-12") + pd.Timedelta('22H') If I then add: shifted_idx = idx +…
mch56
  • 742
  • 6
  • 24
1
vote
1 answer

Can we assign the calendar of pandas.DatetimeIndex as 'noleap' ? or Can datetime.timedelta skip Feb 29th

My pandas dataframe has DatetimeIndex: DatetimeIndex(['1950-02-07', '1951-12-30, '1952-03-04',..............'2020-04-07'], dtype='datetime64[ns]', length=589, freq=None)) I would like to shift the index by using timedelta by days=-4 in no-leap 365…
linyenheng
  • 33
  • 3