我想使用GroupByRolling来计算timeseries的尾部cummax,如
import time
import pandas as pd
df_example = pd.DataFrame({"value": np.random.normal(1500), "group": 1500 * ["A"]})
t = time.process_time()
df_example["value"].rolling(100).apply(lambda x: x.cummax().max(), raw=False)
elapsed_time = time.process_time() - t
print(elapsed_time)
这正是我所期望的,即计算滚动cummax,但我没有找到一个避免groupby和apply组合的实现方法,这两种方法都很慢,在本例中,在我的计算机上需要0.75秒
谢谢你的想法
目前没有回答
相关问题 更多 >
编程相关推荐