3

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?

user3656142
  • 437
  • 3
  • 14
  • 1
    If this is time, location, speed data, wouldn't you want to interpolate the location as well? – it's-yer-boy-chet Aug 15 '19 at 23:43
  • @it's-yer-boy-chet yeah that's a valid point. I was planning to take the initial `lat` `long` values and get the bearing of the interpolated points from the existing point's bearing. And removing the `ID` shouldn't affect much. Let me try this out. – user3656142 Aug 16 '19 at 00:01
  • If you did want to go through with your original plan I think the best move would be to merge the lat/long data back onto the interpolated data set on the date part (ie the second). – it's-yer-boy-chet Aug 16 '19 at 00:04

0 Answers0