6
什么是计算熊猫0.8中TimeSeries的时间加权平均值的最有效方法?例如,假设我想要的df.y - df.x
时间加权平均如下创建:大熊猫的时间加权平均值
import pandas
import numpy as np
times = np.datetime64('2012-05-31 14:00') + np.timedelta64(1, 'ms') * np.cumsum(10**3 * np.random.exponential(size=10**6))
x = np.random.normal(size=10**6)
y = np.random.normal(size=10**6)
df = pandas.DataFrame({'x': x, 'y': y}, index=times)
我觉得这种操作应该是很容易做到的,但一切我试过涉及几个凌乱和缓慢的类型转换。
谢谢!我想通过持续时间对值进行加权,所以我使用了'np.average((df.y - df.x)[: - 1],weights = np.diff(df.index.asi8))' – user2303