In this notebook, we'll walk through some basics of Pandas, Geopandas, and displaying your data with MatPlotLib.
Start by importing pandas, geopandas, and matplotlib:
>>> import pandas as pd
>>> import geopandas as gpd
>>> import matplotlib.pyplot as plt
>>> import os
import pandas as pd
import geopandas as gpd
import matplotlib.pyplot as plt
import os
It is important that we reset our working directory to the home folder. Use os.chdir() to move back one directory.
>>> os.chdir('../')
>>> os.getcwd()
os.chdir('../')
os.getcwd()
>>> gpd.read_file('workshopdata/Boulder_Co.shp')
gpd.read_file('workshopdata/Boulder_Co.shp')
>>> county = gpd.read_file('workshopata/Boulder_Co.shp')
county = gpd.read_file('workshopdata/Boulder_Co.shp')
>>> county
county
>>> county.plot()
county.plot()
>>> county.plot(color='green')
county.plot(color='green')
>>> county.plot(color='green', edgecolor='black', alpha=0.5, figsize=(10,10))
county.plot(color='green', edgecolor='black', alpha=0.5, figsize=(10,10))
county.crs
>>> city = gpd.read_file('workshopdata/City_Limites.shp')
>>> city
city = gpd.read_file('workshopdata/City_Limits.shp')
city
There are five polygons representing the city limits.
Use len to check how many rows there are in a Pandas/GeoPandas dataframe:
>>> len(city)
len(city)
>>> city.plot()
city.plot()
>>> city[0:5]
>>> city[0:]
>>> city[1:3]
>>> city[:5]
>>> city[:-2]
city[0:5]
>>> city[1:3].plot()
city[1:3].plot()
Start by making the county variable the plot "axis", then plot city using county as the axis...
>>> ax = county.plot()
>>> city.plot(ax=ax)
ax = county.plot()
city.plot(ax=ax)
city.crs
>>> city = city.to_crs(county.crs)
>>> city.crs
city = city.to_crs(county.crs)
city.crs
>>> ax = county.plot()
>>> city.plot(ax=ax)
ax = county.plot()
city.plot(ax=ax)
>>> ax = county.plot(color='green', edgecolor='black', alpha=0.5, figsize=(10,10))
>>> city.plot(ax=ax, color='none', edgecolor='white')
ax = county.plot(color='green', edgecolor='black', alpha=0.5, figsize=(10,10))
city.plot(ax=ax, color='none', edgecolor='white')