Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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