Database System Concepts
Database System Concepts
7th Edition
ISBN: 9780078022159
Author: Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher: McGraw-Hill Education
Bartleby Related Questions Icon

Related questions

Question
100%

python: numpy

def purchases(transactions):
"""
QUESTION 7
- A high-end store is trying to evaluate the total amount that customer's spend per transaction. They
want customers to spend anywhere between 130ドル and 150ドル on average.
- You need to determine whether the average number spent on each transaction per month is above, between, or
below the desired amount.
- Transactions is a numpy array containing a date, total amount earned each month, and total
number of transactions each month.
- Above: month's average amount spent per transaction > 150
- Within Range: 150 >= month's average amount spent per transaction >= 130
- Below: month's average amount spent per transaction < 130
- Return a numpy array with "Above", "Within Range" and "Below" for the average amount spent per transaction per month
- THIS MUST BE DONE IN ONE LINE
HINT: use np.where() and convert the type of each column to float

Args:
transactions (np.array)
Returns:
np.array

>> transactions = np.array([['01-31-2022', 5462101, 24752],
['02-28-2022', 7081547.30, 34615],
['03-31-2022', 3287654.57, 16588],
['04-30-2022', 8725851.81, 45621],
['05-31-2022', 6730748.72, 26741],
['06-30-2022', 9562745.43, 76436],
['07-31-2022', 8641735.21, 61448],
['08-31-2022', 7641748.57, 52846],
['09-30-2022', 7645277.02, 65457],
['10-31-2022', 9416274.67, 65109],
['11-30-2022', 9841378.97, 57254],
['12-31-2022', 10654298.18, 98651]])

>> purchases(transactions)
['Above' 'Above' 'Above' 'Above' 'Above' 'Below' 'Within Range'
'Within Range' 'Below' 'Within Range' 'Above' 'Below']

"""
# transactions = np.array([['01-31-2022', 5462101, 24752],
# ['02-28-2022', 7081547.30, 34615],
# ['03-31-2022', 3287654.57, 16588],
# ['04-30-2022', 8725851.81, 45621],
# ['05-31-2022', 6730748.72, 26741],
# ['06-30-2022', 9562745.43, 76436],
# ['07-31-2022', 8641735.21, 61448],
# ['08-31-2022', 7641748.57, 52846],
# ['09-30-2022', 7645277.02, 65457],
# ['10-31-2022', 9416274.67, 65109],
# ['11-30-2022', 9841378.97, 57254],
# ['12-31-2022', 10654298.18, 98651]])
# print(purchases(transactions))

Expert Solution
Check Mark
Algorithm
  1. Define a function "purchases" that takes in a numpy array "transactions" as input.
  2. Use np.where() to determine whether the average amount spent per transaction per month is "Above", "Within Range", or "Below".
  3. Convert the columns of the numpy array "transactions" to float using the astype() method.
  4. Calculate the average amount spent per transaction per month by dividing the total amount earned each month by the total number of transactions each month.
  5. Use np.where() to determine whether the average amount spent per transaction per month is "Above", "Within Range", or "Below" based on the desired range of 130ドル to 150ドル.
  6. Return a numpy array with the results.
Knowledge Booster
Background pattern image
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
    SEE MORE QUESTIONS
    Recommended textbooks for you
    Text book image
    Database System Concepts
    Computer Science
    ISBN:9780078022159
    Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
    Publisher:McGraw-Hill Education
    Text book image
    Starting Out with Python (4th Edition)
    Computer Science
    ISBN:9780134444321
    Author:Tony Gaddis
    Publisher:PEARSON
    Text book image
    Digital Fundamentals (11th Edition)
    Computer Science
    ISBN:9780132737968
    Author:Thomas L. Floyd
    Publisher:PEARSON
    Text book image
    C How to Program (8th Edition)
    Computer Science
    ISBN:9780133976892
    Author:Paul J. Deitel, Harvey Deitel
    Publisher:PEARSON
    Text book image
    Database Systems: Design, Implementation, & Manag...
    Computer Science
    ISBN:9781337627900
    Author:Carlos Coronel, Steven Morris
    Publisher:Cengage Learning
    Text book image
    Programmable Logic Controllers
    Computer Science
    ISBN:9780073373843
    Author:Frank D. Petruzella
    Publisher:McGraw-Hill Education