GeoPandas is an extension of Pandas that adds support for geographic data. It provides a GeoDataFrame data structure, which combines the functionality of Pandas DataFrames with geometric operations provided by the Shapely library. GeoPandas simplifies the manipulation and analysis of geospatial data, making it accessible to a wider audience of data scientists and analysts.
import geopandas as gpd
from shapely.geometry import Point
# Create a GeoDataFrame with points
data = {'City': ['New York', 'Los Angeles', 'Chicago'],
'Latitude': [40.7128, 34.0522, 41.8781],
'Longitude': [-74.0060, -118.2437, -87.6298]}
geometry = [Point(lon, lat) for lon, lat in zip(data['Longitude'], data['Latitude'])]
geo_df = gpd.GeoDataFrame(data, geometry=geometry)
# Create a GeoDataFrame with a world map
world = gpd.read_file(gpd.datasets.get_path('naturalearth_lowres'))
# Plot the world map and cities
world.plot()
geo_df.plot(marker='o', color='red', markersize=50, ax=plt.gca())
plt.show()
This example demonstrates using GeoPandas for working with geospatial data:
Feel free to run this code in a Python environment with GeoPandas and Matplotlib installed to explore the capabilities of GeoPandas for geospatial data analysis!
To install GeoPandas, you can use the following command:
pip install geopandas