1

I have a series indexed by timestamp

    date    value
    t1      x1
    t2      x2
    t3      x3
    ...

I would like to group the series by hours or days and apply a function group-wise that calculates the ratio

(value of the last timestamp in group - value of the first timestamp in group) / (last timestamp - first timestamp)

How can I do this?

Air
  • 8,274
  • 2
  • 53
  • 88
Hello lad
  • 17,344
  • 46
  • 127
  • 200
  • 1
    possible duplicate of [Python Pandas: Group datetime column into hour and minute aggregations](http://stackoverflow.com/questions/16266019/python-pandas-group-datetime-column-into-hour-and-minute-aggregations) - you can see an example of how to solve this in the answer to the question – Jeff Tratner Aug 10 '14 at 03:34
  • @JeffTratner it is not exact a duplicate, because I need also a way to grab the datetime start/end information in each group Thank you – Hello lad Aug 10 '14 at 04:20
  • the difficult part of the problem is to do that grouping, the datetime info in the start and end you can g – Jeff Tratner Aug 10 '14 at 04:45

1 Answers1

0

(last timestamp - first timestamp)

I'm assuming you mean value of timestamp?

It's possible I've misinterpreted the problem, but this might give you an idea.

df.resample('1H', how=lambda x: (x[-1] - x[0]) / (df[-1] - df[0]))
Easypeasy
  • 150
  • 2
  • 11