[英]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.