Question: In Python Problem 3 A) Create a dictionary called counties_cases using a for statement. Specifically, there will be 5 key:value pairs using the strings in
In Python
Problem 3
A) Create a dictionary called counties_cases using a for statement. Specifically, there will be 5 key:value pairs using the strings in counties and integers in cases. If you are unable code the solution, then create the dictionary manually, without a for statement (for partial credit), and move on to the next part. Print out counties_cases. Print the length of counties_cases using the len function.
In [ ]:
# Definition of counties and cases
counties = ['Fairfax', 'Prince William', 'Virginia Beach',
'Loudoun', 'Arlington']
cases = [ 66703, 39398, 30652, 23126, 13182]
# Enter your code below this line:
B) Show which keys are in counties_cases by calling the keys() method on counties_cases. Print out the result. Print out the value that belongs to the key 'Fairfax'.
In [ ]:
C) Update the counties_cases dictionary to include Richmond as the key and its paired value of 14849. Print out counties_cases. Print the length of counties_cases using the len function.
In [ ]:
Problem 4
Create a user defined function that will return a list with all its elements with all string values converted to lower case. Name this function as your first name (your actual first name as on your Mason ID). Then call the function and pass cases as an argument.
In [ ]:
cases = ['Fairfax', 66703, 'Prince William', 39398,
'Virginia Beach', 30652, 'Loudoun', 23126,
'Arlington', 13182, "Richmond", 14849]
#Enter your code below this line:
Problem 5
In [ ]:
The code in this cell will be used for the next
remaining code cells below, but first use the multi-line comment style
to comment out these instructions you are reading. Next,
run this cell and view the dataframe to get an idea
of the data.
import pandas as pd
df = pd.read_csv("https://raw.githubusercontent.com/mwaskom/seaborn-data/master/tips.csv") print(df.head())
A) Use the shape and dtype attributes to print the shape of the dataframe and the data types for each column.
In [ ]:
B) Create a subset named day_tips to only include the data for day and tip columns from df. Print the first three rows using loc. Print the last three rows using iloc.
In [ ]:
C) Use the groupby method on day_tips to group by day and include the describe method to show the summary statistics on the tip column.
In [ ]:
D) Subset df to store all data related to Saturday (Sat). Name this subset sat. Then use the tail() method on sat.
In [ ]:
End of Problems
Run this last cell before submitting your work to Blackboard:
In [ ]:
import pandas as pd
print(pd.to_datetime('today')) import os
cwd = os.getcwd()
print(cwd)
start = "\033[1m"
print(start + f" Thank you, {name}. Save your file as a pdf.") print("Upload both the ipynb and pdf files to Blackboard.") Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
