I am trying to perform a linear interpolation in Python such that the interpolated values are calculated off certain values in a certain column.
In my example below, I want to interpolate Measurements for Products "a", and "b" using the actual numerical values from the relevant cells in Height column in the interpolation. Could I call the Height column the index for the interpolation?
When I am interpolating the missing Measurements for Product "a", the index values to use in interpolation are 4, 5 and 7. For interpolation of Product "b", index values to use are 1, 2.2 and 3.
I know about dataframe.interpolate() but I am struggling to modify my code to use the correct index values.
Here is the code for the dataframe I am starting with:
import pandas as pd
testdata1 = [('Product', ['a', 'a', 'a', 'b', 'b', 'b','b']),
('Height', ['4', '5', '7', '1', '2.2', '3','4']),
('Measurement', ['35.00', '', '55.00','10.00','','30.00','40.00']),
]
df = pd.DataFrame.from_items(testdata1)
df
And here is the code for the dataframe I need:
targetdf = [('Product', ['a', 'a', 'a', 'b', 'b', 'b','b']),
('Height', ['4', '5', '7', '1', '2.2', '3','4']),
('Measurement', ['35.00', '41.67', '55.00','10.00','22.00','30.00','40.00']),
]
df2 = pd.DataFrame.from_items(targetdf)
df2
If this cannot be done with a dataframe, I am open to other ideas to do it in Python.
Any help is greatly appreciated. I am new to Python. Thank you.

