select t1.[name], count(*) - 1 as number_of_aliases, sum(t2.number_of_passengers) as number_of_passengers, avg(t2.avg_ticket_price) as avg_ticket_price
from #tmp t1
left join your_table t2 on t1.[name] like '%' + t2.[name] + '%'
group by t1.[name]
order by t1.[name]
比方说,上面是我的数据帧,我需要重新采样数据6小时,所以对于9:00,该值应该是9,10,11,12,13,14的数据的平均值。 同样地,对于10,该值应该是10,11,12,13,14,15 ......等数据的平均值.......
答案 0 :(得分:3)
您可以使用S2
:
rolling.mean
使用df.set_index('Timestamp').rolling('6h').mean()
Value
Timestamp
2017-11-22 09:00:00 12.356965
2017-11-22 10:00:00 19.527696
2017-11-22 11:00:00 17.402832
2017-11-22 12:00:00 16.908419
2017-11-22 13:00:00 16.558952
2017-11-22 14:00:00 16.638890
2017-11-22 15:00:00 16.418625
2017-11-22 16:00:00 12.837002
2017-11-22 17:00:00 11.649211
2017-11-22 18:00:00 10.121633
2017-11-22 19:00:00 11.226932
2017-11-22 20:00:00 9.896151
+ asfreq
+ rolling.mean
shift
结果与之前相同,但移动了5个位置。