Skip to content

Instantly share code, notes, and snippets.

@MarcinMoskala
Created June 6, 2020 08:39
Show Gist options
  • Save MarcinMoskala/01a8dc86c1ff6ce4b38a9eb06526f06c to your computer and use it in GitHub Desktop.
Save MarcinMoskala/01a8dc86c1ff6ce4b38a9eb06526f06c to your computer and use it in GitHub Desktop.
from pandas import read_csv
crimes_df = read_csv("CrimeData.csv")
crimes_df = crimes_df[crimes_df.year <= "2019"]
days_df = read_csv("DaysData.csv")
from datetime import datetime
def to_weekday(date):
return datetime.strptime(date, "%m/%d/%Y").strftime("%A")
crimes_df["weekday"] = crimes_df.date.map(to_weekday)
crimes_count_df = crimes_df \
.groupby(["weekday"]) \
.size() \
.to_frame("crimes") \
.reset_index()
print(crimes_count_df.to_string())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment