How do I group lat-lon pairings in a Pandas DataFrame?

Danny David Leybzon

I have a dataframe that looks like:

lon        lat
-77.487    39.044
-77.487    39.044
-122.031   37.354
-77.487    39.044

I want to group these lon-lat pairings with a resulting count, like so:

lon        lat      count
-77.487    39.044   3
-122.031   37.354   1

How can I do this? The group() function only appears to allow for grouping by one column.

Nickil Maveli

You could use groupby.size and rename the column created followed by reset_index to get back the desired dataframe.

print(df.groupby(['lon', 'lat']).size().rename('count').reset_index())

       lon     lat  count
0 -122.031  37.354      1
1  -77.487  39.044      3

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How do I place the point of a leaflet marker on given lat/lon coordinates?

From Dev

Google maps javascript - Marker array, how do I get the lat/lon?

From Dev

How do I select the subset of my lat/lon data that is highway travel using R?

From Dev

Using Leaflet.js how do I get map lat/lon on drag end?

From Dev

Google maps javascript - Marker array, how do I get the lat/lon?

From Dev

How could I drag a marker, and get the lon/lat

From Dev

How could I drag a marker, and get the lon/lat

From Dev

How can i show the watchposition lat lon on the map

From Dev

How to do a transpose a dataframe group by key on pandas?

From Dev

How do I get the first timestamp (index) of a group when applying groupby to a python pandas dataframe?

From Dev

How to get lat and lon geolocation coordinates?

From Dev

How to plot on maps from arraylist with lon/lat?

From Dev

How do I group rows in pandas?

From Dev

AngularJS, Leaflet. How can I get lat and lon coordinates dynamically from a third-party service?

From Dev

How can I get a list of (lat, lon) pairs for a way in a single call to the OSM API?

From Dev

Google Earth - How can I insert multiples of the same placemark model at different lat/lon coordinates?

From Dev

iOS: How can i get "GPS lon" and "GPS lat" from this array?

From Dev

How do I columnwise reduce a pandas dataframe?

From Dev

How do I write a pandas dataframe to Vertica?

From Dev

How do I reshape or pivot a DataFrame in Pandas

From Dev

How do i sort the values in a dataframe in pandas?

From Dev

pandas: how do I select first row in each GROUP BY group?

From Dev

How do I turn pandas DataFrame groupby results into a DataFrame?

From Dev

How do I group dataframe columns based on their sequence relation

From Dev

How do I aggregate by group and add the column to the dataframe?

From Dev

Convert point to lat lon

From Dev

How to convert a rotated NetCDF back to a normal lat/lon grid?

From Dev

How to join ggplot (having lon, lat and fill value) with ggmap?

From Dev

How to calculate distance between multiple lon lat vectors using R

Related Related

  1. 1

    How do I place the point of a leaflet marker on given lat/lon coordinates?

  2. 2

    Google maps javascript - Marker array, how do I get the lat/lon?

  3. 3

    How do I select the subset of my lat/lon data that is highway travel using R?

  4. 4

    Using Leaflet.js how do I get map lat/lon on drag end?

  5. 5

    Google maps javascript - Marker array, how do I get the lat/lon?

  6. 6

    How could I drag a marker, and get the lon/lat

  7. 7

    How could I drag a marker, and get the lon/lat

  8. 8

    How can i show the watchposition lat lon on the map

  9. 9

    How to do a transpose a dataframe group by key on pandas?

  10. 10

    How do I get the first timestamp (index) of a group when applying groupby to a python pandas dataframe?

  11. 11

    How to get lat and lon geolocation coordinates?

  12. 12

    How to plot on maps from arraylist with lon/lat?

  13. 13

    How do I group rows in pandas?

  14. 14

    AngularJS, Leaflet. How can I get lat and lon coordinates dynamically from a third-party service?

  15. 15

    How can I get a list of (lat, lon) pairs for a way in a single call to the OSM API?

  16. 16

    Google Earth - How can I insert multiples of the same placemark model at different lat/lon coordinates?

  17. 17

    iOS: How can i get "GPS lon" and "GPS lat" from this array?

  18. 18

    How do I columnwise reduce a pandas dataframe?

  19. 19

    How do I write a pandas dataframe to Vertica?

  20. 20

    How do I reshape or pivot a DataFrame in Pandas

  21. 21

    How do i sort the values in a dataframe in pandas?

  22. 22

    pandas: how do I select first row in each GROUP BY group?

  23. 23

    How do I turn pandas DataFrame groupby results into a DataFrame?

  24. 24

    How do I group dataframe columns based on their sequence relation

  25. 25

    How do I aggregate by group and add the column to the dataframe?

  26. 26

    Convert point to lat lon

  27. 27

    How to convert a rotated NetCDF back to a normal lat/lon grid?

  28. 28

    How to join ggplot (having lon, lat and fill value) with ggmap?

  29. 29

    How to calculate distance between multiple lon lat vectors using R

HotTag

Archive