pandas.DataFrame.rolling不使用巨大的浮点数

kar*_*ren 6 python time-series pandas rolling-average

当使用接近无穷大的浮点数时,我有一个大熊猫滚动的错误.我在这里显示一个例子:

import pandas as pd
series = pd.Series(1.,index = pd.date_range('2015-01-01', periods=6))
series[series.index[2]] = 1e19
series
2015-01-01    1.000000e+00
2015-01-02    1.000000e+00
2015-01-03    1.000000e+19
2015-01-04    1.000000e+00
2015-01-05    1.000000e+00
2015-01-06    1.000000e+00
Freq: D, dtype: float64
series.rolling('2D', closed = 'left').mean()
2015-01-01             NaN
2015-01-02    1.000000e+00
2015-01-03    1.000000e+00
2015-01-04    5.000000e+18
2015-01-05    5.000000e+18
2015-01-06    5.000000e-01
Freq: D, dtype: float64
Run Code Online (Sandbox Code Playgroud)

最后一点的答案应该是1!但它是0.5.为什么在使用大数字时滚动疯狂?相同的例子与较小的浮动:

series[series.index[2]] = 1e9
series.rolling('2D', closed = 'left').mean()
2015-01-01            NaN
2015-01-02            1.0
2015-01-03            1.0
2015-01-04    500000000.5
2015-01-05    500000000.5
2015-01-06            1.0
Freq: D, dtype: float64
Run Code Online (Sandbox Code Playgroud)

Pal*_*Pal 1

问题不在于熊猫。我在 R 中使用 rollmean 函数尝试了同样的事情,它给出了与 pandas 完全相同的结果。它不适用于 1e16 及以上的值。我认为这与系统如何处理浮动有关。