Skip to content

Instantly share code, notes, and snippets.

Avatar

Marcin Moskała MarcinMoskala

View GitHub Profile
View by_tepmerature_by_category.py
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
View by_temp.py
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
View by_weekday.py
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")
View crimes_by_month.py
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
View crimes_by_month.py
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
View by_year_by_type.py
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
View by_month_by_category.py
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
View by_year.py
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
View by_year_by_category.py
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
View by_year.py
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