R 语言 转为python moving range
R语言转成python. 求助
R 语言如下
SmovM <- data.frame(movM %>% group_by(Parameter,Step,filename)%>% mutate(row=row_number(),avg=zoo::rollmean(Value,k=7,fill = NA,align = "center"),
std=zoo::rollapply(Value, width=15, FUN=sd, fill=NA,align = "center")))
大概是新建三列对么? python 用agg 实现?底下R 中的Width 相当于窗宽?
movM = movM.groupby((['Parameter','Step','filename']).agg(row = row_number(),avg = ('Value','rolling(window=7,center=True).mean()'), std = ('Value','rolling(window=15,center=True).std()'))下面这个提示AttributeError: 'float' object has no attribute 'rolling'
def moving_rolling(x):
return x['Value'].rolling(window=7,center=True).mean(),x['Value'].rolling(window=15,center=True).std()
movM[['avg','std']] = movM.apply(moving_rolling, axis = 1,result_type="expand")
pandas API as below:
DataFrame.rolling(window, min_periods=None, center=False, win_type=None, on=None, axis=0, closed=None, method='single')
#zoo::rollapply(Value, width=15, FUN=sd, fill=NA,align = "center"
以上是 R 语言 转为python moving range 的全部内容, 来源链接: utcz.com/p/938163.html