Time-weighted average with Pandas

后端 未结 1 648
野的像风
野的像风 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)
提交回复
热议问题