Interpolate Between Two Nearby Rows Of Dataframe
I would like to interpolate missing values within groups in dataframe using preceding and following rows value. Here is the df (there are more records within a group but for this e
Solution 1:
df['Xval-1'] = df['Xval'].shift(-1)
df['Xval+1'] = df['Xval'].shift(+1)
df['Yval-1'] = df['Yval'].shift(-1)
df['Yval+1'] = df['Yval'].shift(+1)
df["PTC_interpol"] = df.apply(lambda x: np.interp(x['Xval'], [x['Xval-1'], x['Xval+1']], [x['Yval-1'], x['Yval+1']]), axis=1)
df['PTC'] = np.where(df['PTC'].isnull(), df["PTC_interpol"], df['PTC'])
Post a Comment for "Interpolate Between Two Nearby Rows Of Dataframe"