Worksheet 1
Worksheet 1#
This worksheet is due Tuesday of Week 2, before discussion section. You are encouraged to work in groups of up to 3 total students, but each student should submit their own file. (It’s fine for everyone in the group to upload the same file.)
These questions refer to the attached vending machines csv file, vend.csv.
How many locations are there in the dataset? (In other words, how many unique values are there in the “Location” column?) Set the variable
a
to be equal to this integer.Assume
df_sub
is the sub-DataFrame ofdf
corresponding to the transactions at the"Earle Asphalt"
location, given bydf[df["Location"] == "Earle Asphalt"]
. What values ofb
andc
are such thatdf_sub.loc[13, "Transaction"]
is equal todf_sub.iloc[b,c]
? (Remember that counting in Python starts at 0.)There is exactly one row where the
"RPrice"
is not equal to the"MPrice"
. What is the index of that row? Setd
to be equal to that index.What was the average price of the sales at
"EB Public Library"
on"Friday, July 1, 2022"
? (We haven’t discussed how to compute averages. You might be able to guess an approach that works, or usedir
, or Google search.) Round your answer to the nearest penny. (You can round a floatx
to two decimal places with the commandround(x,2)
.) Sete
to be equal to this rounded average.Put these five numbers (four integers and one float) into a tuple,
my_tuple = (a,b,c,d,e)
.Save
my_tuple
in a pickle file named"wkst1-ans.pickle"
using the following code. Submit that file on Canvas as your submission for Worksheet 1.
import pickle
with open("wkst1-ans.pickle", 'wb') as f:
pickle.dump(my_tuple, f)
If you want to double-check that this
"wkst1-ans.pickle"
pickle file really contains your answer, you can run the following code. If you then evaluate or printx
, you should see your originalmy_tuple
values. (If you’re in a new notebook, you also need to import the pickle module again.)
with open("wkst1-ans.pickle", 'rb') as f:
x = pickle.load(f)