rolling-computation

Pandas Dataframe rolling with two columns and two rows

被刻印的时光 ゝ 提交于 2019-12-01 17:54:27
问题 I got a dataframe with two columns that are holding Longitude and Latitude coordinates: import pandas as pd values = {'Latitude': {0: 47.021503365600005, 1: 47.021503365600005, 2: 47.021503365600005, 3: 47.021503365600005, 4: 47.021503365600005, 5: 47.021503365600005}, 'Longitude': {0: 15.481974060399999, 1: 15.481974060399999, 2: 15.481974060399999, 3: 15.481974060399999, 4: 15.481974060399999, 5: 15.481974060399999}} df = pd.DataFrame(values) df.head() Now I want to apply a rolling window

the rolling regression in R using roll apply

时间秒杀一切 提交于 2019-11-30 19:49:11
My imported data contains 7 variables: Y and X1 , X2 , X3 , X4 , X5 , X6 . I tried applying the rollapply function in zoo in order to run a rolling regression within an in-sample with a window of 262 obs. (work days in a year). date Y X1 X2 1 10/1/07 -0.0080321720 4.690734e-03 3.333770e-03 2 10/2/07 0.0000000000 -2.818413e-03 5.418223e-03 3 10/3/07 0.0023158650 -4.178744e-03 -3.821100e-04 4 10/4/07 -0.0057491710 -5.071030e-03 -8.321550e-04 5 10/5/07 0.0073570500 3.065045e-03 5.179574e-03 6 10/8/07 0.0127708010 -7.278513e-03 1.145395e-03 7 10/9/07 0.0032661980 9.692267e-03 6.514035e-03 8 10/10

R: create a data frame out of a rolling window

谁说胖子不能爱 提交于 2019-11-30 14:07:20
Lets say I have a data frame with the following structure: DF <- data.frame(x = 0:4, y = 5:9) > DF x y 1 0 5 2 1 6 3 2 7 4 3 8 5 4 9 what is the most efficient way to turn 'DF' into a data frame with the following structure: w x y 1 0 5 1 1 6 2 1 6 2 2 7 3 2 7 3 3 8 4 3 8 4 4 9 Where w is a length 2 window rolling through the dataframe 'DF.' The length of the window should be arbitrary, i.e a length of 3 yields w x y 1 0 5 1 1 6 1 2 7 2 1 6 2 2 7 2 3 8 3 2 7 3 3 8 3 4 9 I am a bit stumped by this problem, because the data frame can also contain an arbitrary number of columns, i.e. w,x,y,z etc.

the rolling regression in R using roll apply

拥有回忆 提交于 2019-11-30 03:28:26
问题 My imported data contains 7 variables: Y and X1 , X2 , X3 , X4 , X5 , X6 . I tried applying the rollapply function in zoo in order to run a rolling regression within an in-sample with a window of 262 obs. (work days in a year). date Y X1 X2 1 10/1/07 -0.0080321720 4.690734e-03 3.333770e-03 2 10/2/07 0.0000000000 -2.818413e-03 5.418223e-03 3 10/3/07 0.0023158650 -4.178744e-03 -3.821100e-04 4 10/4/07 -0.0057491710 -5.071030e-03 -8.321550e-04 5 10/5/07 0.0073570500 3.065045e-03 5.179574e-03 6 10

rolling regression by group in the tidyverse?

孤者浪人 提交于 2019-11-29 10:04:55
There are many questions about rolling regression in R, but here I am specifically looking for something that uses dplyr , broom and (if needed) purrr . This is what makes this question different. I want to be tidyverse consistent. Is is possible to do a proper running regression with tidy tools such as purrr:map and dplyr ? Please consider this simple example: library(dplyr) library(purrr) library(broom) library(zoo) library(lubridate) mydata = data_frame('group' = c('a','a', 'a','a','b', 'b', 'b', 'b'), 'y' = c(1,2,3,4,2,3,4,5), 'x' = c(2,4,6,8,6,9,12,15), 'date' = c(ymd('2016-06-01', '2016

Python - rolling functions for GroupBy object

邮差的信 提交于 2019-11-28 18:12:32
I have a time series object grouped of the type <pandas.core.groupby.SeriesGroupBy object at 0x03F1A9F0> . grouped.sum() gives the desired result but I cannot get rolling_sum to work with the groupby object. Is there any way to apply rolling functions to groupby objects? For example: x = range(0, 6) id = ['a', 'a', 'a', 'b', 'b', 'b'] df = DataFrame(zip(id, x), columns = ['id', 'x']) df.groupby('id').sum() id x a 3 b 12 However, I would like to have something like: id x 0 a 0 1 a 1 2 a 3 3 b 3 4 b 7 5 b 12 Note: as identified by @kekert, the following pandas pattern has been deprecated. See

rolling regression by group in the tidyverse?

三世轮回 提交于 2019-11-28 00:19:50
问题 There are many questions about rolling regression in R, but here I am specifically looking for something that uses dplyr , broom and (if needed) purrr . This is what makes this question different. I want to be tidyverse consistent. Is is possible to do a proper running regression with tidy tools such as purrr:map and dplyr ? Please consider this simple example: library(dplyr) library(purrr) library(broom) library(zoo) library(lubridate) mydata = data_frame('group' = c('a','a', 'a','a','b', 'b

Python - rolling functions for GroupBy object

空扰寡人 提交于 2019-11-27 10:16:47
问题 I have a time series object grouped of the type <pandas.core.groupby.SeriesGroupBy object at 0x03F1A9F0> . grouped.sum() gives the desired result but I cannot get rolling_sum to work with the groupby object. Is there any way to apply rolling functions to groupby objects? For example: x = range(0, 6) id = ['a', 'a', 'a', 'b', 'b', 'b'] df = DataFrame(zip(id, x), columns = ['id', 'x']) df.groupby('id').sum() id x a 3 b 12 However, I would like to have something like: id x 0 a 0 1 a 1 2 a 3 3 b