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 of df corresponding to the transactions at the "Earle Asphalt" location, given by df[df["Location"] == "Earle Asphalt"]. What values of b and c are such that df_sub.loc[13, "Transaction"] is equal to df_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? Set d 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 use dir, or Google search.) Round your answer to the nearest penny. (You can round a float x to two decimal places with the command round(x,2).) Set e 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 print x, you should see your original my_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)
Created in deepnote.com Created in Deepnote