Search code examples
pythonpandasdataframeplotgeopandas

Geopandas data not plotting correctly


I don't have very much experience with GeoPandas at all, so I am a little lost. I am trying to plot this data

jupyterNotebook dataframe image

I have followed many references on the GeoPandas website, read through blog posts, and this stack overflow post. All of them tell me to do the same thing, but it seems to still now be working. Ploting data in geopandas

When I try to plot this data, it comes out this like: enter image description here

All I am trying to do is plot points from this csv file that has latitude and longitude data onto a map (eventually a map that I have loaded from an .shp file).

Anyways, here is the code I have written so far:

import csv
import geopandas as gpd
import pandas as pd
import matplotlib.pyplot as plt
import descartes
from shapely.geometry import Point, Polygon

#Load in the CSV Bike Station Location Data
df = pd.read_csv('HRSQ12020.csv')

#combine the latitude and longitude to make coordinates
df['coordinates'] = df[['Longitude', 'Latitude']].values.tolist()

# Change the coordinates to a geoPoint
df['coordinates'] = df['coordinates'].apply(Point)
df
#convert df to a geodf
df = gpd.GeoDataFrame(df, geometry='coordinates')
df

#plot the geodf
df.plot(figsize=(20,10));

Any ideas what is wrong? I check all 100 coordinates and they all seem to be fine. Any suggestions would be great! Thanks!


Solution

  • It's likely to be a problem of projection system. A good thing to do is defining immediately the crs when creating a Geopandas object. If you try,

    df = gpd.GeoDataFrame(df, geometry='coordinates', crs = 4326)
    

    maybe you will be able to see your points. I put "4326" because your x-y coordinates look like GPS coordinates which are WSG84 standards (crs code: 4326). Change to the relevent crs code if it's not the good one.