0

Suppose I have two dataframe df1 and df2

In df1 date value 0 2018-01-23 10:00:00 10 1 2018-01-23 11:00:00 20 2 2018-01-23 12:00:00 30

In df2 date value 0 2018-01-23 10:02:00 10 1 2018-01-23 10:03:00 20 2 2018-01-23 10:04:00 30 3 2018-01-23 10:05:00 40 4 2018-01-23 10:06:00 50 5 2018-01-23 11:07:00 50 ...

Update:

I want to calculate the summation of df2.value based on the interval selected by df1.date.iloc[n-1] and df1.date.iloc[n]. I can get index of df2.date by IntervalIndex but unable to select the value inside each interval.

dexhunter
  • 578
  • 8
  • 24
  • Tl;dr, build an IntervalIndex from the df.date and df.date.shift(-1). – cs95 Jan 23 '18 at 04:44
  • @cᴏʟᴅsᴘᴇᴇᴅ Thank you for pointing out the direction. After using `IntervalIndex` how do I calculate the summation of 'df2.value' based on IntervalIndex? For example, at [2018-01-23 10:00:00, 2018-01-23 11:00:00], summation of `df2.value` would be 150. I am still not sure how to select the time range using IntervalIndex. Shouldn't it be `df2.loc[idx.get_indexer(df2.date), "value"]` where `idx = pd.IntervalIndex.from_arrays(df1.date, df.date.shift(1))`? – dexhunter Jan 23 '18 at 07:46
  • @cᴏʟᴅsᴘᴇᴇᴅ I found your link does not work, there are skipped `df1.value` and I don't need to join two dataframes. – dexhunter Jan 24 '18 at 06:31

0 Answers0