繁体   English   中英

非时间序列的pandas数据框重采样列

[英]pandas dataframe resample column of non-timeseries

我有两组数据(数据帧),每组都有彼此相关的两列(让它们分别称为x和y),例如:

设置1:

x   |   y
0.1 |   1
0.2 |   2
0.3 |   3
0.4 |   2
0.5 |   3
0.6 |   4
0.7 |   5

第2组:

x    |   y
0.12 |   0
0.21 |   2
0.31 |   5
0.44 |   4
0.52 |   3
0.61 |   1
0.76 |   1

我想将两个集合的y值相加(等于x个点),但是x稍微未对齐。 为了解决这个问题,我认为最好以0.001的步长将x = 0.12到0.7的两个集合内插,基本上是:

mini = max(set1.x.min(), set2.x.min())
maxi = max(set1.x.max(), set2.x.max())
x_interpolation_points = np.arange(maxi, mini, 0.001)

# Next step: interpolate both sets
# last step: sumY = set1.y + set2.y

如何做到这一点? 如果是时间表,我会使用resample()。interpolate(),但这不是时间表。

最后,我使用numpy解决了它:numpy.interp()

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM