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
2
votes
1 answer

Merging two DataFrames on DatetimeIndex

I haven't had problems with such DataFrame operations until now. What I'm trying to achieve, is to get a DataFrame, containing daily data for a few years period and hourly data for the last 5 days. My code (fully running): import yfinance as…
mldc
  • 31
  • 3
2
votes
1 answer

Calculate the amount of time that a column was positive before reverting to 0

I have a table containing non-negative values against a datetimeindex, like the following: CapturableSeparation date 2021-02-23 18:09:00 0.00 2021-02-23 18:10:00 0.00 2021-02-23 18:11:00 0.04 2021-02-23 18:12:00…
Cole MG
  • 317
  • 2
  • 13
2
votes
1 answer

Pandas Approximate Frequency Per Year of a DateTimeIndex

I have a multiple Timeseries in different files and I know that Pandas can infer the frequency of the DateTimeIndex for each: pd.infer_freq(data.index) Is there a programmatic way to get the approximate frequency per year from general files. For…
rhaskett
  • 1,864
  • 3
  • 29
  • 48
2
votes
1 answer

dataframe: how to get columns of Period objects (calendar+fiscal year and month)from DatetimeIndex?

I have a dataframe and these are the first 5 index, there are several rows with different datapoint for a date and then it goes to the next day DatetimeIndex(['2014-01-01', '2014-01-01', '2014-01-01', '2014-01-01', '2014-01-01'], …
neutralname
  • 383
  • 2
  • 4
  • 11
2
votes
2 answers

What's the difference between changing datetime string to datetime by pd.to_datetime & datetime.strptime()

I have a df that looks similar to this (shortened version, with less rows): Time (EDT) Open High Low Close 0 02.01.2006 19:00:00 0.85224 0.85498 0.85224 0.85498 1 02.01.2006 20:00:00 0.85498 0.85577 0.85423 0.85481 2 …
saga
  • 736
  • 2
  • 8
  • 20
2
votes
1 answer

How to find missing days or hours that breaks continuity in Datetime index?

Many thanks in advance for helping a python newbie like me ! I have a DataFrame containing daily or hourly prices for a particular crypto. I was just wondering if there is an easy way to check if there is any missing day or hour (depending on the…
plonfat
  • 413
  • 1
  • 5
  • 10
2
votes
2 answers

Creating pandas DatetimeIndex in Dataframe from DST aware datetime objects

From an online API I gather a series of data points, each with a value and an ISO timestamp. Unfortunately I need to loop over them, so I store them in a temporary dict and then create a pandas dataframe from that and set the index to the timestamp…
Timm
  • 202
  • 1
  • 11
2
votes
1 answer

Integrating over x values of type pandas.Datetime

I am trying to do some integration with np.trapz of some data using DatetimeIndex as x values, but the results are not what I was expecting. Could somebody maybe help me out? The problem: I got a pandas dataframe which has a timestamps as indexes…
2
votes
1 answer

Get column with cumulative business day for each month from pandas datetimeindex

I am trying to get similar output to df.index.day but with the number corresponding to the business day. So for 2020-04-06 I want 4 instead of 6. I appreciate the help. Solution: for i in range(len(df_21)): if ((i == 0) | (df_21.month[i-1] !=…
2
votes
2 answers

Averaging values of dates in dataframe

I have the following dataframe data = pd.DataFrame({ 'date': ['1988/01/12', '1988/01/13', '1988/01/14', '1989/01/20','1990/01/01'], 'value': [11558522, 12323552, 13770958, 18412280, 13770958] }) Is there a way in python that I can average a value…
Tamarie
  • 125
  • 2
  • 6
  • 18
2
votes
1 answer

How to avoid confusion between column and DatetimeIndex when adding column to Pandas dataframe

I have a pandas DataFrame with column headers that are numerical strings and an index that is a DatetimeIndex. For example: In: df=pd.DataFrame([[1,2,3],[4,5,6],[7,8,9]], index=pd.DatetimeIndex(['2019-01-01 00:00:00', '2019-01-01 00:05:00', …
doctorer
  • 1,672
  • 5
  • 27
  • 50
2
votes
2 answers

Formatting DateTimeIndex

I am new to Python and struggle with a seemingly simple problem. I am trying to change the format of the DateTimeIndex to show only years and months. I am still returned the original format (YYYY-MM-DD). Thank you in advance. from numpy import…
PRA
  • 29
  • 2
2
votes
1 answer

Remove n following rows in time indexed Pandas dataframe based on value in above row

Working on Pandas and need to remove the n consecutive rows in the DataFrame based on value in column. In the example bellow, there is an event at 17:00:01 that last for 2 sec. I need the following 2 rows in that times span dropped. There is another…
user6453877
  • 314
  • 1
  • 4
  • 14
2
votes
2 answers

How to resample the dataframe without changing it's core?

How to resample the dataframe without changing it's core? import pandas as pd import sys if sys.version_info[0] < 3: from StringIO import StringIO else: from io import StringIO csvdata =…
Thiago AV
  • 55
  • 4
2
votes
1 answer

Assigning datetime as index does not give DatetimeIndex

My df has a field called "days". I need to create a datetime from "days" and a startdate. Probably cumbersome, but it works: for t in df.index: df.loc[t,'date']=datetime.date(startdate)+ …
Wesley Kitlasten
  • 417
  • 5
  • 15