Honors Course #3
Lab Six
Welcome to DATA 101 lab six, an individual OR partner lab, your choice. Either way, it will be collected on Tuesday, November 26th at 11:59pm. Good luck!
You are what you eat
In the cell below, create a string variable called my_name
which has your full name. (If you're doing this lab with a partner, instead create a NumPy array called our_names
with two strings in it.)
Also in the cell below, create a Pandas series called "my_food
" with three elements: the index of this series should be the values pizza
, burgers
, and sushi
, in that order. The corresponding values of the series should be the approximate number of pieces of pizza, hamburgers, and pieces of sushi you estimate you have eaten in your lifetime. (If you're doing this lab with a partner, instead create a Pandas DataFrame with two columns, one with the first name of partner #1 and the other with the first name of partner #2. The index of the DataFrame should still be as specified above.)
---------------------------------------------------------------------------
NameError Traceback (most recent call last)
<ipython-input-36-37e6c44faca7> in <module>()
2
3 fam['cornwell']=('mary')
----> 4 fam=fam.add(other='age',fill_value=na)
5 print(fam)
NameError: name 'na' is not defined
Highly functioning
Write a function called triple_it()
that takes a single numeric argument (which you can name whatever you want), and returns triple its value. (For example, calling triple_it(4)
should return the number 12.)
Make sure to also write code to test this function (i.e., call the function for a few sample values, and print the answer it returns) to make sure it works.
Write a function called mpg()
that takes three arguments: start_mileage
, which is the starting mileage on a car's odometer; end_mileage
, which is the ending mileage on a car's odometer; and gallons
, which is the number of gallons of gas it took to drive that distance. It should return the miles per gallon for the car.
Needless to say, you should also write code to test this function.
Write a function called lucky_add()
that takes two numeric arguments (which you can name whatever you want), and returns their sum, unless their sum is 13, in which case it returns 0.
Needless to say, you should also write code to test it.
Write a function called salutation()
which takes three arguments: gender
(male
, female
, or other
), marital_status
(single
, married
, divorced
, or widowed
), and degree
(None
, AA
, BA
, BS
, MA
, MS
, or PhD
). It should return the string "Dr."
for Ph.D.'s, "Mr."
for all other males, "Mx."
for all people with "other
" gender, "Miss"
for single females, "Mrs."
for married females, and "Ms."
for other females. (Yes, we did this example in class and in the book. Try to do it yourself again without looking, though, and then look if you need to.)
Needless to say.
In the U.S. tax code, a taxpayer's AGI (Adjusted Gross Income) is (basically) the sum of their year's wages and tips, minus any alimony they received and any retirement contributions they made. Write a function called agi()
which takes four arguments -- a taxpayer's wages, tips, alimony, and retirement contributions -- and returns their AGI.
Needless to.
In the U.S. tax code, a taxpayer's taxable income is their AGI minus their deductions. Deductions can be either "standard" or "itemized." For taxpayers who itemize their deductions, their deduction is simply the amount they itemized (duh). In 2019, the standard deduction (for non-itemizers) is either $12,200 (for taxpayers less than 65 years old) or else $14,000 (for those 65 years or older).
Write a function called taxable_income()
that takes three numeric arguments: a taxpayer's AGI, itemized deductions, and age. It should return their taxable income. For itemized deductions equal to 0, use the taxpayer's standard deduction in the calculation. Otherwise, use their itemized deductions.
Needless.
Taxation without representation
The file peeps.csv
in your lab6 folder contains fictitious information about 17,185 made-up taxpaying Americans. Read it into a DataFrame
called peeps
, and spend a minute inspecting its contents.
Print a message to the screen giving the lowest, highest, and median age of the taxpayers in this data set.
Print out a little table that shows how many males, females, and other-gendered people there are.
Display a bar chart that shows how many people with each type of college degree there are.
Display a histogram that shows how common various amounts of income are ("income" is wages plus tips).
Print out a little table that shows how many people of each gender received alimony.
How many taxpayers in this data set are named "Stephen Davies
?" Print a message to the screen with that information.
Financial advisors say that you really ought to put at least 10% of your income towards retirement if you don't want to be a leech on society when you're older. How many of these taxpayers are actually doing that? Print a message to the screen with information about what percentage (not a raw total) of these taxpayers are socking away at least that much. (To be clear, the message could be something like: "Only 73.9% of these taxpayers are saving the recommended 10%!"
)
Create a new column in this DataFrame
called Honorific
that contains each taxpayer's form of address as defined in your salutation()
function.
What percent of these taxpayers go by either "Mr." or "Mrs."? Print a message to the screen with that information.
Write a loop that will print a message for each taxpayer with last name "Potter"
or "Granger"
that says (for instance) "You earned $59182 this year, Mr. Frodo P. Granger!"
The number printed should be the taxpayer's income (wages plus tips), and their full name should appear as in that example, with all four components.
Create a new column in this DataFrame
called AGI
that contains each taxpayer's AGI as defined in your agi()
function.
Create a new column in this DataFrame
called TaxableIncome
that contains each taxpayer's taxable income as defined in your taxable_income()
function.
Is taxable income significantly associated/correlated with marital status? Perform this analysis and print a message to the screen giving the answer.
Is taxable income significantly associated/correlated with age? Perform this analysis and print a message to the screen giving the answer.
Is taxable income significantly different between those with Associates Degrees and those with Bachelors Degrees? Perform this analysis and print a message to the screen giving the answer.