why does pandas rolling use single dimension ndarray

后端 未结 4 1048
清歌不尽
清歌不尽 2020-11-29 02:12

I was motivated to use pandas rolling feature to perform a rolling multi-factor regression (This question is NOT about rolling multi-factor reg

4条回答
  •  暖寄归人
    2020-11-29 02:40

    Since pandas v0.23 it is now possible to pass a Series instead of a ndarray to Rolling.apply(). Just set raw=False.

    raw : bool, default None

    False : passes each row or column as a Series to the function.

    True or None : the passed function will receive ndarray objects instead. If you are just applying a NumPy reduction function this will achieve much better performance. The raw parameter is required and will show a FutureWarning if not passed. In the future raw will default to False.

    New in version 0.23.0.

    As noted; if you only need one single dimension, passing it raw is obviously more efficient. This is probably the answer to your question; Rolling.apply() was initially built to pass an ndarray only because this is the most efficient.

提交回复
热议问题