pandas .resample()方法的R等效项是什么?

编程入门 行业动态 更新时间:2024-10-25 03:16:12
本文介绍了pandas .resample()方法的R等效项是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

这是我找到的最接近的链接: stats.stackexchange/questions/5305/how-to-re-sample-an-xts-time-series-in-r

This is the closest link I've found: stats.stackexchange/questions/5305/how-to-re-sample-an-xts-time-series-in-r

但是我没有看到关于在熊猫中可以汇总数据的不同方式(例如均值,计数,匿名函数)的任何信息.

But I don't see anything about the different ways to aggregate the data (like mean, count, anonymous function) which you can do in pandas.

对于我的程序,我试图让一个数据帧每2分钟重新采样一次,并取每个间隔的2个值的平均值.谢谢!

For my program, I'm trying to have a dataframe be resampled every 2 minutes and take the average of the 2 values at each interval. Thanks!

推荐答案

如果您使用data.table和lubridate,它可能看起来像这样

If you use data.table and lubridate it might look something like this

library(data.table) library(lubridate) #sample data dt<-data.table(ts=seq(from=ymd('2015-01-01'), to=ymd('2015-07-01'),by='mins'), datum=runif(260641,0,100))

如果您希望从分钟到每小时获取数据,则可以这样做

if you wanted to get the data from minute to hourly means you could do

dt[,mean(datum),by=floor_date(ts,"hour")]

如果您有一堆列,并且希望将它们平均化,则可以这样做

if you had a bunch of columns and you wanted all of them to be averaged you could do

dt[,lapply(.SD,mean),by=floor_date(ts,"hour")]

您可以将mean替换为所需的任何功能.您可以将小时"替换为秒",分钟",小时",天",周",月",年".好吧,您不能从几分钟到几秒钟,因为那需要魔术,但无论如何您可以从微秒到几秒.

You can replace mean for any function you'd like. You can replace "hour" with "second", "minute", "hour", "day", "week", "month", "year". Well you can't go from minute to seconds as that would require magic but you can go from micro seconds to seconds anyway.

不可能将序列从较低的周期转换为 较高的周期性-例如每周至每天或每天至5分钟吧, 因为那需要魔法.

It is not possible to convert a series from a lower periodicity to a higher periodicity - e.g. weekly to daily or daily to 5 minute bars, as that would require magic.

-来自xts手册的Jeffrey Ryan.

-Jeffrey Ryan from xts manual.

我从没学过xts,所以我不知道使用xts对象的语法,但是那行很著名(或者至少和手册中的那行一样著名)

I never learned xts so I don't know the syntax to do it with xts objects but that line is famous (or at least as famous as a line from a manual can be)

更多推荐

pandas .resample()方法的R等效项是什么?

本文发布于:2023-10-07 15:33:25,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1469789.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:方法   pandas   resample

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!