Created
June 6, 2020 08:39
-
-
Save MarcinMoskala/01a8dc86c1ff6ce4b38a9eb06526f06c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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