I have a lot of geographic data as shown below. I would like to group data using trays at 2 degrees in longitude and a width of .2 degrees in latitude.
While it is trivial to do for latitude or longitude, what is most suitable for this for both variables?
|User_ID |Latitude |Longitude|Datetime |u |v |
|---------|----------|---------|-------------------|-----|-----|
|222583401|41.4020375|2.1478710|2014-07-06 20:49:20|0.3 | 0.2 |
|287280509|41.3671346|2.0793115|2013-01-30 09:25:47|0.2 | 0.7 |
|329757763|41.5453577|2.1175164|2012-09-25 08:40:59|0.5 | 0.8 |
|189757330|41.5844998|2.5621569|2013-10-01 11:55:20|0.4 | 0.4 |
|624921653|41.5931846|2.3030671|2013-07-09 20:12:20|1.2 | 1.4 |
|414673119|41.5550136|2.0965829|2014-02-24 20:15:30|2.3 | 0.6 |
|414673119|41.5550136|2.0975829|2014-02-24 20:16:30|4.3 | 0.7 |
|414673119|41.5550136|2.0985829|2014-02-24 20:17:30|0.6 | 0.9 |
So far I have created 2 linear spaces:
lonbins = np.linspace(df.Longitude.min(), df.Longitude.max(), 10)
latbins = np.linspace(df.Latitude.min(), df.Latitude.max(), 10)
Then I can use groupBy:
groups = df.groupby(pd.cut(df.Longitude, lonbins))
Then I could obviously sort out the groups to create a second level. My goal is to do a statistical analysis for each of the groups and, possibly, display them on a map, this is not very convenient.
bucket = {}
for name, group in groups:
print name bucket[name] = group.groupby(pd.cut(group.Latitude, latbins))
For example, I would like to make a heat map that will display the number of lines in each tray, display the speed distribution in each of the trays, ...