Created
June 6, 2020 08:04
-
-
Save MarcinMoskala/1bcdf66c7a7de4fd6a7085872a785a89 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| def add_day_month_year(df): | |
| dates = df["Date"].map(lambda x: x[:10]) | |
| df["day_of_month"] = dates.map(lambda x: x.split("/")[1]) | |
| df["month"] = dates.map(lambda x: x.split("/")[0]) | |
| df["year"] = dates.map(lambda x: x.split("/")[2]) | |
| df["date"] = dates | |
| return df | |
| from pandas import read_csv | |
| crimes_df = read_csv("CrimeData.csv") | |
| crimes_df = add_day_month_year(crimes_df) | |
| crimes_df = crimes_df[crimes_df.year <= "2019"] | |
| crimes_df = crimes_df[crimes_df.type == "BATTERY"] # "THEFT"... | |
| days_df = read_csv("DaysData.csv") | |
| crimes_count_df = crimes_df \ | |
| .groupby(["year"]) \ | |
| .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