让我们想象一下,我有一个时间序列的温度传感器数据,每隔30分钟一次。如何将每隔30分钟的温差划分为较小的5分钟间隔,同时考虑到各间隔之间的温差差异?
我想,做这样的事是可行的:
区间1:温度= 30间隔2:温度= 25
区间1:温度= 30间隔2:温度= 29间隔3:温度= 28间隔4:温度= 27间隔5:温度= 26间隔6:温度= 25
发布于 2021-12-17 16:54:42
我会将数据帧重采样到更低的时间分辨率(在本例中,“6T”,有T表示分钟),这将创建新的行,用于丢失nan值的时间步骤,然后您可以以某种方式填充那些nan,因为我认为线性插值就足够了。
这里有一个简单的例子,我认为它可以与您描述的数据相匹配。
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()发布于 2021-12-17 16:51:30
如果您可以包括两件事的示例,这将是有帮助的:
你的数据看起来像什么currently?
否则,不清楚你在问什么或问题是什么,所以很难帮助你!
https://stackoverflow.com/questions/70396252
复制相似问题