Question: Exercise 1 Fill in the blanks to create three new variables named regular _ price, loyalty _ price, and coupon _ price according to the
Exercise
Fill in the blanks to create three new variables named regularprice, loyaltyprice, and couponprice
according to the following logic:
regularprice salesvalue retaildisc couponmatchdisc quantity
loyaltyprice salesvalue couponmatchdisc quantity
couponprice salesvalue coupondisc quantity
and then perform the following analyses:
Identify the five households with the largest loyaltyprice transactions. What is unique about the
transaction with the largest loyaltyprice value?
Now filter for only those observations where quantity was greater than Now which households
have the largest loyaltyprice transaction?
Using the first transaction in the result from # filter the products data based on the productid
to find out which product the largest loyaltyprice transaction is associated with.
# Q: Create three new variables named regularpriceloyaltyprice and
# couponprice according to the logic shown above
transactions transactions
mutate
regularprice
loyaltyprice
couponprice
selectregularprice, loyaltyprice, couponprice, productid everything
# Q Identify the five households with the largest loyaltyprice transactions. What
# is unique about the transaction with the largest loyaltyprice value?
transactions
slicemaxorderby loyaltyprice, n
# Q Now filter for only those observations where quantity was greater than Now which
# households have the largest loyaltyprice transaction?
transactions
filterquantity
slicemaxorderby n
# Q Using the first transaction in the result from # filter the products data based
# on the productid to find out which product the largest loyaltyprice transaction
# is associated with.
products
filterproductid
Exercise
transactions includes unique product IDs. How many of these products not transactions! had a
regular price of one dollar or less? How many of these products had a loyalty price of one dollar or less?
How about a coupon price of one dollar or less?
Hint: After filtering, select the productid column and count unique products using the ndistinct
function.
# how many products had a regular price of $ or less
transactions
filterregularprice
selectproductid
ndistinct
# how many products had a loyalty price of $ or less
transactions
filter
selectproductid
# how many products had a coupon price of $ or less
transactions
filter
Exercise
What proportion of baskets are over $ in sales value? What proportion of baskets are over $ in sales
value?
Hint: You need to use groupby and summarize Depending on your approach you may or may not
use mutate
# test your ability to right this code from scratch rather than just
# filling in the blanks :
Exercise
Which stores had the largest total salesvalue hint: sumsalesvalue, narm TRUE Which stores
had the largest average loyalty discount as defined below?
Hint: You can calculate loyalty discount as a percentage of regular price using the following logic:
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
