Home > database >  Get approx value from dataframe
Get approx value from dataframe

Time:03-30

I'd like to get the "Distance" value for a given "LapTimeSeconds" that isn't present in the table, is there any way to do that?

Maybe using interpolation? But how? Thanks in advance

# Something like this?
driver1_tel.loc[(driver1_tel["LapTimeSeconds"] == (3.0)]

Dataframe

CodePudding user response:

You could just use scipy's interpolate function on the columns of interest. From looking at what you have written it would go something like:

from scipy import interpolate
x = df.LaptimeSecond
y = df.Distance
f = interpolate.interp1d(x, y)
ynew = f(3)

The variable ynew would give you the interpolated distance for a laptime of 3 seconds.

  • Related