-2

I have a problem, that should be typical in science but I couldn't find a solution yet.

I have a data set in a cvs file, e.g.: enter image description here

What I need is to bring the data in this format, so I can directly compare them with other data, because they have the same x values: enter image description here

The y values should be a linear interpolation from the original data. I'm complete open to any python package (numpy, pandas, scipy,...).

I have a solution in excel but I want to automate that step, as I collect all the data in python.

Thank you in advance

Olli

Oliver W
  • 7
  • 1
  • 1
    Please [edit] to include your sample input and output data in the text of your question, not as a picture or link, to make a [mcve] – G. Anderson Feb 04 '21 at 19:52

1 Answers1

2

Numpy has a nice way of doing it:

import numpy as np

x = [0, 0.53, 0.84, 1.25, 1.55]
y = [0.523, 0.723, 0.965, 1.251, 1.458]

new_x = [0, 0.5, 1.0, 1.5]
new_y = np.interp(new_x, x, y)

new_y
Stefan
  • 897
  • 4
  • 13
  • 2
    I would just like to add you'll probably end up generating `new_x` with `np.linspace`. Here it'd be `np.linspace(0, 1.5, 4)`. – orlp Feb 04 '21 at 19:56