I have a dataframe like this:
Time ID lat long speed
0 27619 1471777 23289.639077 18234.769277 2.25
1 27620 1471777 23287.585417 18238.259976 4.05
2 27621 1471777 23284.390833 18243.689952 6.30
3 27622 1471777 23280.192238 18250.826491 8.28
4 27623 1471777 23276.536215 18257.040797 7.21 ...contd
I needed to interpolate along the speed column and the command I found just works with TimeSeries. So I first removed the ID
,lat
and long
columns and made the Time
column my axis. Assuming the dataframe is referred as a
,
drop_col = ['ID', 'lat', 'long']
a.drop(drop_col,axis=1,inplace=True)
a['Time'] = a['Time'].astype('float64')
a['Time'] = pd.to_datetime(a["Time"], unit='s')
a = a[set_index('Time').resample(rule='0.25S').mean().interpolate(method='linear') # works when a datetime object is the index
I had to remove the 3 columns as otherwise those columns would have been extrapolated too. After having the extrapolated speeds, I add an acceleration
column so the df looks like this:
rows speed acceleration
1 2.7000 0.45
2 3.1500 0.45
3 3.6000 0.45
4 4.0500 0.45
5 4.6125 0.56 ...contd
However, I now need to calculate the heading between two points (i.e. between two successive rows) and for that I need the columns lat
and long
(stands for latitude and longitude) that I had dropped to avoid unwanted interpolation.
So, is there a method that would directly allow me to interpolate along just the speed axis, so that I can keep the latitude and longitude values constant for the interpolated rows?