import geopandas
# Pull in example dataset of NYC Boroughs
path_to_data = geopandas.datasets.get_path("nybb")
gdf = geopandas.read_file(path_to_data)
gdf
BoroCode | BoroName | Shape_Leng | Shape_Area | geometry | |
---|---|---|---|---|---|
0 | 5 | Staten Island | 330470.010332 | 1.623820e+09 | MULTIPOLYGON (((970217.022 145643.332, 970227.... |
1 | 4 | Queens | 896344.047763 | 3.045213e+09 | MULTIPOLYGON (((1029606.077 156073.814, 102957... |
2 | 3 | Brooklyn | 741080.523166 | 1.937479e+09 | MULTIPOLYGON (((1021176.479 151374.797, 102100... |
3 | 1 | Manhattan | 359299.096471 | 6.364715e+08 | MULTIPOLYGON (((981219.056 188655.316, 980940.... |
4 | 2 | Bronx | 464392.991824 | 1.186925e+09 | MULTIPOLYGON (((1012821.806 229228.265, 101278... |
geopandas.datasets.available
['naturalearth_cities', 'naturalearth_lowres', 'nybb']
# Writing files (defaults to shapefile but can be changed, e.g., driver="GeoJSON")
gdf.to_file("Data/myfile.shp")
gdf.to_file("Data/my_file.geojson", driver="GeoJSON")
gdf.plot();
gdf = gdf.set_index("BoroName")
gdf["area"] = gdf.area
gdf["area"]
BoroName Staten Island 1.623822e+09 Queens 3.045214e+09 Brooklyn 1.937478e+09 Manhattan 6.364712e+08 Bronx 1.186926e+09 Name: area, dtype: float64
gdf.plot("area", legend=True);
# Interactive maps
gdf.explore("area", legend=False)