利用geopandas,在地图上绘制经纬度的点

利用geopandas,在地图上绘制经纬度的点

使用的数据集

这里使用的是Gowalla的签到数据集,链接: 数据链接.

引入必要的包

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

读取数据

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

利用geopandas,在地图上绘制经纬度的点_第1张图片

从pandas 里的经纬度转换为geoDataFrame

"""
由于数据集太大,这里取部分数据进行绘制
"""
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')

plt.show()

显示效果

利用geopandas,在地图上绘制经纬度的点_第2张图片

参考geopandas官方文档的代码: 官方链接.

你可能感兴趣的:(数据挖掘,数据挖掘,python,可视化,数据可视化)