Calling external function on pandas dataframe column

182 Views Asked by At

I have a dataframe that looks like this: df

Index   timestamp       name latitude   longitude
0   2019-08-03 04:50:12 1   36.82454681 24.96810198
1   2019-08-03 04:50:20 1   36.82462692 24.96758223
2   2019-08-03 04:50:29 1   36.82474136 24.96686697
3   2019-08-03 04:50:40 1   36.82484436 24.96621704
4   2019-08-03 08:50:41 1   36.82494354 24.96556711
5   2019-08-03 08:50:42 1   36.82505035 24.96491718
6   2019-08-03 08:50:43 1   36.82514191 24.96433306
7   2019-08-03 04:50:44 1   36.82524872 24.9636879
8   2019-08-03 04:51:49 2   36.82555771 24.96175003
9   2019-08-03 04:52:00 2   36.82566833 24.96104002
10  2019-08-03 04:52:20 2   36.82586288 24.95981693
11  2019-08-03 04:52:30 2   36.82597733 24.95910788

I want to apply a function which I installed from pip (https://pypi.org/project/rdp/). It is used to reduce the number of points in a curve. When I do:

from rdp import rdp
RDP_out = rdp(df[['latitude','longitude']].to_numpy(),epsilon=0.00005)

It works for all points in the dataset. But, I want to apply the function rdp on the unique column values 'name' within a 3 hour window for all rows in the dataframe. Any idea how I do this?

0

There are 0 best solutions below