Reputation: 181
I have a time series dataset where the pickup and drop off latitude and longitude coordinates are given. Since coordinates of a city hardly vary, how to categorize them in python?
I want to make groups so that Classification algorithm can be applied.
I am pasting a single row of pick up and drop off longitude and latitude coordinates of New York city.
-73.973052978515625 40.793209075927734 -73.972923278808594 40.782520294189453
I have fixed the range of latitude from 40.6 to 40.9 and longitude range from -73.9 to -74.25
Now, I want to make them into groups so that classification algorithm can be applied.
Upvotes: 1
Views: 1730
Reputation: 8599
For example you can insert you coordinates in a list of tuples
called coordinates
. Please note that I have appended also a couple of coordinates out of range. Here is the code:
coordinates = [
(-73.973052978515625,40.793209075927734),
(-73.972923278808594,40.782520294189453),
(-75.9,40.7)
]
filtered = list()
# filtering coordinates
for c in coordinates:
if -74.25 <= c[0] <= -73.9 and 40.6 <= c[1] <= 40.9:
filtered.append(c)
print filtered # here you have your filtered coordinates
Output:
[(-73.97305297851562, 40.793209075927734), (-73.9729232788086, 40.78252029418945)]
Upvotes: 1