首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >Pandas-我如何将时间间隔划分为较小的时间间隔?

Pandas-我如何将时间间隔划分为较小的时间间隔?
EN

Stack Overflow用户
提问于 2021-12-17 16:35:51
回答 2查看 154关注 0票数 0

让我们想象一下,我有一个时间序列的温度传感器数据,每隔30分钟一次。如何将每隔30分钟的温差划分为较小的5分钟间隔,同时考虑到各间隔之间的温差差异?

我想,做这样的事是可行的:

  • 30分钟间隔:

区间1:温度= 30间隔2:温度= 25

  • 5分钟间隔:

区间1:温度= 30间隔2:温度= 29间隔3:温度= 28间隔4:温度= 27间隔5:温度= 26间隔6:温度= 25

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2021-12-17 16:54:42

我会将数据帧重采样到更低的时间分辨率(在本例中,“6T”,有T表示分钟),这将创建新的行,用于丢失nan值的时间步骤,然后您可以以某种方式填充那些nan,因为我认为线性插值就足够了。

这里有一个简单的例子,我认为它可以与您描述的数据相匹配。

代码语言:javascript
运行
复制
import pandas as pd

df = pd.DataFrame({"temp":[30, 25, 20, 18]}, index = pd.date_range("2021-12-01 12:00:00", "2021-12-01 13:59:00", freq = "30T"))

#This resample will preserve your values at their original time indexes, and will create new rows for the intermediate
#datetime full of nans
#the .last() is just used to select the value for each time-step, you could also use mean o max o min or mean as there is just one value for each time step so it would get you the same.
df = df.resample("6T").last()

#it really depends on how you want to implement the change over time of the data, but as you described a linear 
#variation, what you can use is a simple linear interpolation between values with the method interpolate
df.interpolate()
票数 1
EN

Stack Overflow用户

发布于 2021-12-17 16:51:30

如果您可以包括两件事的示例,这将是有帮助的:

你的数据看起来像什么currently?

  • What,你希望它在你做完之后看起来像什么?

否则,不清楚你在问什么或问题是什么,所以很难帮助你!

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/70396252

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档