Homework 6#
Type your name and email in the “Student details” section below.
Develop the code and generate the figures you need to solve the problems using this notebook.
For the answers that require a mathematical proof or derivation you can either:
Type the answer using the built-in latex capabilities. In this case, simply export the notebook as a pdf and upload it on gradescope; or
You can print the notebook (after you are done with all the code), write your answers by hand, scan, turn your response to a single pdf, and upload on gradescope.
The total homework points are 100. Please note that the problems are not weighed equally.
Note
Please match all the pages corresponding to each of the questions when you submit on gradescope.
Student details#
First Name:
Last Name:
Email:
Problem 1 - Loops and conditionals#
Consider the following list:
data = [1, 4, 3, 10, 4, 3, 4, 4]
Write a loop that computes the average of the elements in the list and
printthe result using two significant digits.
# your code here
Write code that finds the number of times the element 4 occurs in the list. Hint: Use a loop and an if-statement.
# your code here
Write a Python function that takes a list as an argument and returns the number of times a given element (also passed as an argument to the function) appears in the list. Call that function
find_number_of_occurences(a, elm). Make sure you follow best practices when writing the docstring of your function.
# your code here
# Try your code here:
help(find_number_of_occurences)
# Try your code here:
find_number_of_occurences(data, 4)
Write a Python function that takes a list as an argument and returns the number of elements that are greater than a given element (also passed as an argument to the function). Call that function
find_number_of_elms_greater_than(a, elm). Make sure you follow best practices when writing the docstring of your function.
# your code here
# Try your code here:
help(find_number_of_elms_greater_than)
# Try your code here:
find_number_of_elms_greater_than(data, 3)
Problem 2 - High-performance buildings revisited#
In this problem we will continue analyzing the high-performance buildings dataset we introduced in Problem 1 - Playing with matrices and with which we played in Selecting dataframe rows that satisfy a boolean expression. Let me set you up by downloading and cleaning the data file:
!curl -O 'https://raw.githubusercontent.com/PurdueMechanicalEngineering/me-239-intro-to-data-science/master/data/temperature_raw.xlsx'
df = pd.read_excel('temperature_raw.xlsx')
df = df.dropna(axis=0)
df.date = pd.to_datetime(df['date'], format='%Y-%m-%d')
df.head()
Plot the external temperature
t_out
# Your code here
Extract the data pertaining to household
a5. Put the result in a new dataframe calleddf_a5.
df_a5 = # Your code here
df_a5.head()
For household
a5, plott_unitas a function of date.
# Your code here
In a single figure, plot
datevst_unitfor householdsa5anda11.
# Your code here
In the same figure, plot the
t_outandt_unitscatter plots for both householdsa5anda11.
# Your code here
In the same figure, plot the
t_outandhvacscatter plots for both householdsa5anda11.
# Your code here
In the same figure, plot the histogram of
t_unitfor householdsa5anda11. Which household prefers cooler temperatures? Hint: To make the histogram more appealing use the keywordsdensity=True, alpha=0.25.
# Your code here
Your answer and explanation here
In the same figure, plot the histogram of
hvacfor householdsa5anda11. Which household is more energy efficient (if any) and why?
# Your code here
your answer and explanation here
Repeat the analysis above for households
b17andc40. Which household prefers cooler temperatures and which one is more energy efficient?
# your code here
Your answer and explanation here. Use as many code and markdown blocks as you want.
Run the following code to convert the notebook to a pdf. Verify that the file path to the notebook is correct.
from google.colab import drive
drive.mount('/content/drive')
!apt-get install inkscape texlive texlive-xetex texlive-latex-extra pandoc --quiet
!pip install pypandoc --quiet
!jupyter nbconvert --to PDF '/content/drive/MyDrive/Colab Notebooks/Copy of homework_06.ipynb'