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 itertools import count, takewhile | |
def frange(start, stop, step): | |
return takewhile(lambda x: x < stop, count(start, step)) | |
def show_avg_hist(df, column, buckets=40): | |
counts = df[column].value_counts() | |
counts = counts[counts > 20] # Drop rare values |
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 itertools import count, takewhile | |
def frange(start, stop, step): | |
return takewhile(lambda x: x < stop, count(start, step)) | |
def show_avg_hist(df, column, buckets=40): | |
counts = df[column].value_counts() | |
counts = counts[counts > 20] # Drop rare values |
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") |
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
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 |
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
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 |
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
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 |
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
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 |
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
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 |
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
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 |
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
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 |
NewerOlder