Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/visual-studio/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python-滚动回归计算坡度的方法_Python_Regression_Nan - Fatal编程技术网

Python-滚动回归计算坡度的方法

Python-滚动回归计算坡度的方法,python,regression,nan,Python,Regression,Nan,是否有通过滚动(窗口=5)回归计算坡度的方法 df A 2016-01-01 5.9 2016-01-02 6.3 2016-01-03 NaN 2016-01-04 5.6 2016-01-05 4.3 2016-01-06 5.6 2016-01-07 4.6 2016-01-08 4.0 2016-01-09 7.0 ... result A 2016-01-01 - 2016-01-02

是否有通过滚动(窗口=5)回归计算坡度的方法

df
              A   
2016-01-01  5.9 
2016-01-02  6.3 
2016-01-03  NaN 
2016-01-04  5.6 
2016-01-05  4.3
2016-01-06  5.6
2016-01-07  4.6
2016-01-08  4.0
2016-01-09  7.0
...

result
              A   
2016-01-01  - 
2016-01-02  - 
2016-01-03  - 
2016-01-04  - 
2016-01-05  NaN
2016-01-06  NaN
2016-01-07  NaN
2016-01-08  xxx 
2016-01-09  xxx
...
#(xxx stands for some value)
我尝试使用linregress计算值,但它在包含NaN的框架中不起作用

如果橱窗里有,就别理Nan

from scipy.stats import linregress
df.apply(lambda v: linregress(df.index, df.A)[0])