for iyear in range(styr,edyr+1): wka = data[data['Year_new']==iyear].copy() diff_max = 0 stdate = 0 for i in range(0,len(wka)-2): t_1 = wka.iloc[i]['TEM_Min'] t_2 = wka.iloc[i+1]['TEM_Min'] t_3 = wka.iloc[i+2]['TEM_Min'] diff = max(t_1-t_2,t_1-t_3,t_2-t_3) if diff > diff_max: diff_max = diff stdate = wka.iloc[i]['date'] out_dw = out_dw.append({'年':wka.iloc[0]['Year_new'],'stdate':stdate,'diff':diff_max},ignore_index=True) out_dw['低温赔付'] = out_dw.apply(lambda x:get_money_dw(x['diff']),axis=1) out_dw.to_csv(str(staCode)+'低温具体赔付详情.csv',encoding='gbk')转成R代码
时间: 2023-06-15 07:07:31 浏览: 185
T+数据字典
3星 · 编辑精心推荐
for (iyear in styr:edyr){
wka <- data[data$Year_new==iyear,]
diff_max <- 0
stdate <- 0
for (i in 1:(nrow(wka)-2)){
t_1 <- wka$TEM_Min[i]
t_2 <- wka$TEM_Min[i+1]
t_3 <- wka$TEM_Min[i+2]
diff <- max(t_1-t_2,t_1-t_3,t_2-t_3)
if (diff > diff_max){
diff_max <- diff
stdate <- wka$date[i]
}
}
out_dw <- rbind(out_dw, data.frame('年'=wka$Year_new[1], 'stdate'=stdate, 'diff'=diff_max))
}
out_dw$低温赔付 <- apply(out_dw, 1, function(x) get_money_dw(x['diff']))
write.csv(out_dw, paste0(staCode, '低温具体赔付详情.csv'), row.names=FALSE, fileEncoding='gbk')
阅读全文