22
loading...
This website collects cookies to deliver better user experience
df2020 = pd.read_csv("https://github.com/nicholasoxford/pythonViz/blob/main/2020-old.csv?raw=true")
df2020.index = pd.to_datetime(df2020["occur_date"])
df2020 = df2020[(df2020.index < "2020-09-10")]
df2020
df2020 = df2020[(df2020.index < "2020-09-10")]
, you will see the entire scope of the file. You'll also notice it only goes to September 30th. The rest of the data is another CSV, titled CRIME-2020. In the read_csv line, switch out the file name at the end for the rest of the years data.def dfGeoTransfer(df):
return gpd.GeoDataFrame(df2021, crs="EPSG:4326", geometry=[Point(xy) for xy in zip(df2021['long'], df2021['lat'])])
geo_df20 = dfGeoTransfer(df2020)
geo_df20
def prepareGeoDataFrame(url):
df = pd.read_csv(url)
df.index = pd.to_datetime(df["occur_date"])
df = df[(df.index < "2020-09-10")]
filter = df["long"] > -84.425
filter2 = df["long"] < -84.35
filter3 = df["lat"] > 33.745
filter4 = df["lat"] < 33.813
df = df[(filter) &(filter2) & (filter3) & (filter4)]
return gpd.GeoDataFrame(df, crs="EPSG:4326", geometry=[Point(xy) for xy in zip(df['long'], df['lat'])])
prepareGeoDataFarame
function. Making sure our data is structured the same will help going forward. Plus, now all we have to do is pass in a URL and the hard work is done for us. df.index = pd.to_datetime(df["occur_date"])
if(df.index.max().year == 2020):
df = df[(df.index < "2020-09-10")]
if(df.index.max().year == 2021):
df = df[(df.index < "2021-09-10")]
filter = df["long"] > -84.425
street_map = gpd.read_file('/content/drive/MyDrive/GC_Roads/GC_RD_GA/Roads_Atlanta_GA.shp')
geo_df20 = prepareGeoDataFrame("https://github.com/nicholasoxford/pythonViz/blob/main/2020-old.csv?raw=true")
geo_df21 = prepareGeoDataFrame("https://github.com/nicholasoxford/pythonViz/blob/main/COBRA-2021%203.csv?raw=true")
fig, (ax1, ax2) = plt.subplots(nrows=1, ncols=2,figsize=(9,9))
#plot both streetmap and and long/lat points
# fig, ax = plt.subplots(figsize=(15,15))
geo_df21.plot(column="UC2_Literal", ax=ax1,alpha=0.5, legend=True,markersize=30)
street_map.to_crs(4326).plot(ax=ax1, alpha=0.4,color='grey')
geo_df20.plot(column="UC2_Literal", ax=ax2,alpha=0.5, legend=True,markersize=30)
street_map.to_crs(4326).plot(ax=ax2, alpha=0.4,color='grey')
fig.tight_layout()