One possible approach:
Format all elements of the series in tuples (x, y, row id), for example. (4, 150, 1) and add them to the list of tuples and sort them in ascending x.
Declare a list with a length equal to the number of rows to maintain the "last seen" value for each series.
Iterate through each element of the list in step (1) and:
3.1 Update the "last time" list according to the series identifier in the tuple
3.2 If the x of the previously iterated tuple does not match the x of the current tuple, summarize the entire element of the "last seen" list and add the result to the final list.
Now with my dirty test:
>>> S1 = ((1, 100), (5, 100), (10, 100)) S2 = ((4, 150), (5, 100), (18, 150)) >>> all = [] >>> for s in S1: all.append((s[0], s[1], 0)) ... >>> for s in S2: all.appned((s[0], s[1], 1)) ... >>> all [(1, 100, 0), (5, 100, 0), (10, 100, 0), (4, 150, 1), (5, 100, 1), (18, 150, 1)] >>> all.sort() >>> all [(1, 100, 0), (4, 150, 1), (5, 100, 0), (5, 100, 1), (10, 100, 0), (18, 150, 1)] >>> last_val = [0]*2 >>> last_x = all[0][0] >>> final = [] >>> for e in all: ... if e[0] != last_x: ... final.append((last_x, sum(last_val))) ... last_val[e[2]] = e[1] ... last_x = e[0] ... >>> final.append((last_x, sum(last_val))) >>> final [(1, 100), (4, 250), (5, 200), (10, 200), (18, 250)] >>>