计算Pandas 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)
Run Code Online (Sandbox Code Playgroud)
我觉得这个操作应该很容易做到,但我尝试过的所有内容都涉及到几个混乱和缓慢的类型转换.
我有一个timestamps在几秒钟内(从午夜开始)的列,具有纳秒级精度34200.934549345, 34205.735545344,在DataFrame中等等df.
这些timestamps来自同一天2011-01-10.
如何以纳秒精度转换这些秒的DateTime64格式为numpy?
我想在我的这些条目 df
2011-01-10 9:30:00.934549345
2011-01-10 9:30:05.735545344
Run Code Online (Sandbox Code Playgroud)
我需要在问题的解决方案下执行类似于此示例中的确切操作.
可能吗?