Read our blogs, tips and tutorials
Try our exercises or test your skills
Watch our tutorial videos or shorts
Take a self-paced course
Read our recent newsletters
License our courseware
Book expert consultancy
Buy our publications
Get help in using our site
548 attributed reviews in the last 3 years
Refreshingly small course sizes
Outstandingly good courseware
Whizzy online classrooms
Wise Owl trainers only (no freelancers)
Almost no cancellations
We have genuine integrity
We invoice after training
Review 30+ years of Wise Owl
View our top 100 clients
Search our website
We also send out useful tips in a monthly email newsletter ...
Software ==> | Python (34 exercises) |
Topic ==> | Overview of NUMPY (2 exercises) |
Level ==> | Average difficulty |
Subject ==> | Python training |
This exercise is provided to allow potential course delegates to choose the correct Wise Owl Microsoft training course, and may not be reproduced in whole or in part in any format without the prior written consent of Wise Owl.
The above folder contains a spreadsheet analysing how many ingredients you buy for your modest pancake stall (Wise Owl are Crepe) in a typical week:
You have lots of supplies of cooking oil and salt in stock, so don't need these.
Create a program called Business Plan.py, and type in the following code (you'll need to change the folder path given):
import pandas as pd
import numpy as np
# read excel into Pandas data frame
temp_df = pd.read_excel('C:\wiseowl\Python\purchases.xlsx')
# convert a data frame to a Numpy 2D array
purchases = np.asarray(temp_df)
This should import the data from the Excel workbook, and convert it (via a Pandas dataframe) to a NumPy array. Print the array to check that this has worked:
Print out the dtype property of the array also to show that the presence of the first column is forcing Python to store the data as type object.
Use slicing to set the value of a new variable called volumes equal to the array above, but minus its first column, then run the following command to convert this array to data type integer:
new_volumes = volumes.astype('I')
Print out the dtype property of this latest array to check that the data is indeed now being held as integers.
Create another array called prices to hold the prices you pay in pounds:
Product | Price you pay |
---|---|
Butter | 2 |
Flour | 1 |
Milk | 1.5 |
Eggs | 1.5 |
Show the shape of each of your two arrays:
This should tell you which order they should go in when you mutliply them together.
Use the dot method to multiply your prices array by your new_volumes array to show your total spending per day, then use the sum method to show your total overall spending:
Your spending is peaking on Friday.
Save your program and close it down (if it's anywhere near lunchtime, maybe it's time to reward yourself with a pancake?).
You can find other training resources for the subject of this exercise here:
Kingsmoor House
Railway Street
GLOSSOP
SK13 2AA
Landmark Offices
99 Bishopsgate
LONDON
EC2M 3XD
Holiday Inn
25 Aytoun Street
MANCHESTER
M1 3AE
© Wise Owl Business Solutions Ltd 2024. All Rights Reserved.