简体   繁体   中英

pandas dataframe resample column of non-timeseries

I have two sets of data (dataframes), each with two columns which relate to eachother (lets call them x and y), like such:

set 1:

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

set 2:

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

I want to sum the y values of both sets (at equal x points), however x is slightly misaligned. To solve this I thought it would be best to interpolate both sets from x = 0.12 to 0.7 in 0.001 steps, essentially:

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

How would one accomplisch this? In case of a timeserie I would use resample().interpolate(), but this is not a timeserie..

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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