Skip to content

Instantly share code, notes, and snippets.

View MarcinMoskala's full-sized avatar

Marcin Moskała MarcinMoskala

View GitHub Profile
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
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
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")
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
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
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
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
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
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
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