In [1]:
import pandas as pd
data = pd.read_csv("../data/GP04/thanksgiving.csv", encoding="Latin-1")
data.head()
Out[1]:
In [2]:
data["Do you celebrate Thanksgiving?"].value_counts()
Out[2]:
In [3]:
data = data[data["Do you celebrate Thanksgiving?"] == "Yes"]
In [4]:
data["What is typically the main dish at your Thanksgiving dinner?"].value_counts()
Out[4]:
In [5]:
data[data["What is typically the main dish at your Thanksgiving dinner?"] == "Tofurkey"]["Do you typically have gravy?"]
Out[5]:
In [6]:
data["Which type of pie is typically served at your Thanksgiving dinner? Please select all that apply. - Apple"].value_counts()
Out[6]:
In [7]:
ate_pies = (pd.isnull(data["Which type of pie is typically served at your Thanksgiving dinner? Please select all that apply. - Apple"])
&
pd.isnull(data["Which type of pie is typically served at your Thanksgiving dinner? Please select all that apply. - Pecan"])
&
pd.isnull(data["Which type of pie is typically served at your Thanksgiving dinner? Please select all that apply. - Pumpkin"])
)
ate_pies.value_counts()
Out[7]:
In [8]:
data["Age"].value_counts()
Out[8]:
In [9]:
def extract_age(age_str):
if pd.isnull(age_str):
return None
age_str = age_str.split(" ")[0]
age_str = age_str.replace("+", "")
return int(age_str)
data["int_age"] = data["Age"].apply(extract_age)
data["int_age"].describe()
Out[9]:
In [10]:
data["How much total combined money did all members of your HOUSEHOLD earn last year?"].value_counts()
Out[10]:
In [11]:
def extract_income(income_str):
if pd.isnull(income_str):
return None
income_str = income_str.split(" ")[0]
if income_str == "Prefer":
return None
income_str = income_str.replace(",", "")
income_str = income_str.replace("$", "")
return int(income_str)
data["int_income"] = data["How much total combined money did all members of your HOUSEHOLD earn last year?"].apply(extract_income)
data["int_income"].describe()
Out[11]:
In [12]:
data[data["int_income"] < 50000]["How far will you travel for Thanksgiving?"].value_counts()
Out[12]:
In [13]:
data[data["int_income"] > 150000]["How far will you travel for Thanksgiving?"].value_counts()
Out[13]:
In [14]:
data.pivot_table(
index="Have you ever tried to meet up with hometown friends on Thanksgiving night?",
columns='Have you ever attended a "Friendsgiving?"',
values="int_age"
)
Out[14]:
In [15]:
data.pivot_table(
index="Have you ever tried to meet up with hometown friends on Thanksgiving night?",
columns='Have you ever attended a "Friendsgiving?"',
values="int_income"
)
Out[15]:
In [ ]: