Time-weighted average with Pandas

后端 未结 1 649
野的像风
野的像风 2020-12-15 00:11

What\'s the most efficient way to calculate the time-weighted average of a TimeSeries in Pandas 0.8? For example, say I want the time-weighted average of df.y - df.x

相关标签:
1条回答
  • 2020-12-15 00:50

    You can convert df.index to integers and use that to compute the average. There is a shortcut asi8 property that returns an array of int64 values:

    np.average(df.y - df.x, weights=df.index.asi8)
    
    0 讨论(0)
提交回复
热议问题