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
38
votes
3 answers

Pandas: Merge data frames on datetime index

I have the following two dataframes that I have set date to DatetimeIndex df.set_index(pd.to_datetime(df['date']), inplace=True) and would like to merge or join on date: df.head(5) catcode_amt type feccandid_amt amount date …
Collective Action
  • 7,607
  • 15
  • 45
  • 60
12
votes
4 answers

From DatetimeIndex to list of times

My objective is to have a lists of times (in seconds), already packaged in lists of times in 5 minutes for a whole day. This is my code to package the whole day of "2016-07-08" by 5 minutes : pd.date_range('2016-07-08 00:00:00', '2016-07-08…
Arij SEDIRI
  • 2,088
  • 7
  • 25
  • 43
12
votes
5 answers

extend a pandas datetimeindex by 1 period

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…
piRSquared
  • 285,575
  • 57
  • 475
  • 624
10
votes
1 answer

pandas grouper vs time grouper

The new pandas version deprecates the TimeGrouper, so we should use the regular Grouper. The old code: df['column_name'].groupby(pd.TimeGrouper("M")).mean().plot() works fine in the old version of pandas. However, none…
Georg Heiler
  • 16,916
  • 36
  • 162
  • 292
10
votes
2 answers

Pandas: DataFrame groupby for year/month and return with new DatetimeIndex

I need some directions in grouping a Pandas DateFrame object by year or month and get in return an new DateFrame object with a new index. Here is my code so far. groupby works as intended. Load data from .csv file, parse 'Date' to date format…
dirk
  • 494
  • 1
  • 3
  • 17
7
votes
1 answer

Python Pandas DatetimeIndex.hour

I am attempting to build 3 separate columns in my dataframe for the value of the time stamp HOUR, DAY, MONTH with the DatetimeIndex. I appologize for data that cant be reproduced because my data set is being read from a CSV File. boilerDf =…
bbartling
  • 3,288
  • 9
  • 43
  • 88
6
votes
1 answer

Trying to debug mixed datetimes and integers in passed array

I have two panda data frames new_hpm and new_mr with datetime index, and I am trying to subset one based on datetime index of another using .loc. The datetime indexes on the two data frames are: new_hpm.index DatetimeIndex(['2013-01-01',…
halo09876
  • 2,725
  • 12
  • 51
  • 71
6
votes
3 answers

Shift time in multi-index to merge

I want to merge two datasets that are indexed by time and id. The problem is, the time is slightly different in each dataset. In one dataset, the time (Monthly) is mid-month, so the 15th of every month. In the other dataset, it is the last business…
Jesse Blocher
  • 523
  • 1
  • 4
  • 16
6
votes
1 answer

How to extend date_range in Pandas Dataframe?

Some data are collected every 5 seconds and sometimes are missing. After loading them into a Pandas dataframe, I want to define a starting point in time and extract exactly 180 rows (15 minutes x 12 samples per minute), whatever the starting point.…
Alex Poca
  • 2,406
  • 4
  • 25
  • 47
6
votes
1 answer

time slice on second level of multiindex

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…
Brian
  • 1,555
  • 3
  • 16
  • 23
5
votes
2 answers

Pandas Timestamp rounds 30 seconds inconsistently

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…
Peter
  • 107
  • 5
5
votes
2 answers

List of dates from DatetimeIndex object

I have a DatetimeIndex object comprised of two dates given as follows: import pandas as pd timestamps = pd.DatetimeIndex(['2014-1-1', '2014-1-2'], freq='D') which looks like this: DatetimeIndex(['2014-01-01', '2014-01-02'], dtype='datetime64[ns]',…
ajrlewis
  • 2,968
  • 3
  • 33
  • 67
5
votes
3 answers

Select Range of DatetimeIndex Rows Using .loc (Pandas Python 3)

Working with a pandas series with DatetimeIndex. Desired outcome is a dataframe containing all rows within the range specified within the .loc[] function. When I try the following code: aapl.index =…
anon
  • 159
  • 2
  • 3
  • 9
5
votes
3 answers

How to get last day of each month in Pandas DataFrame index (using TimeGrouper)

I have a DataFrame with incomplete dates and I only need the date/row of the last day available of each month. I tried using TimeGrouper and take .last() of each group. import pandas as pd idx =…
cxwf
  • 329
  • 1
  • 3
  • 12
5
votes
1 answer

Pandas: Accessing data with list of dates and DateTimeIndex

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…
user3142067
  • 1,222
  • 3
  • 13
  • 26
1
2 3
21 22