How to use geopandas to draw latitude and longitude points on the map

created at 07-02-2021 views: 6

Data set used

The sign-in data set of Gowalla is used here, link: data link.

Introduce the necessary packages

import pandas as pd
import geopandas
import matplotlib.pyplot as plt

Read data

df_checkin =  pd.read_csv('./Gowalla_totalCheckins.txt',sep='\t',header=None)
df_checkin.columns= ['user','check_in_time','latitude','longitude','location_id']

data structure

Convert latitude and longitude in pandas to geoDataFrame

Because the data set is too large, here is part of the data for drawing
df_checkin_ = df_checkin[df_checkin.user==0]
gdf_ = geopandas.GeoDataFrame(
    df_checkin_, geometry=geopandas.points_from_xy(df_checkin_.longitude, df_checkin_.latitude))
world = geopandas.read_file(geopandas.datasets.get_path('naturalearth_lowres'))

# We restrict to South America.
ax = world.plot(
    color='white', edgecolor='black',figsize=(30,30))

# We can now plot our ``GeoDataFrame``.
gdf_.plot(ax=ax, color='red')

show the result:

 the result


geopandas docs

created at:07-02-2021
edited at: 07-02-2021: