How to linearly interpolate a new column from existing columns?
Add a new column between the two existing ones filled with NaN
values and then use interpolate
with axis=1
:
df.insert(1, 'intreped_X', np.nan)
df.interpolate(axis=1)
Result:
X1 intreped_X X2
0 34.5 35.40 36.3
1 12.4 11.85 11.3
2 16.5 16.20 15.9
3 8.5 8.30 8.1
4 56.6 56.10 55.6