Acme, Inc. has provided you with a CSV file containing the following fields for a number of orders:
- region
- country
- item_type
- sales_channel
- order_id
- units_sold (int)
- unit_price (float)
- unit_cost (float)
- total_revenue (float)
- total_cost (float)
- total_profit (float)
They would like you to process this data to provide them with a number of insights.
Use OOP to find the result of:
- The total number of units sold across all orders
- The total amount of profit across all orders
- The number of online orders that were made in Hungary
- The
order_id
of the order that generated the highest profit (Harder!)
In addition, they would like you to generate a dictionary where each key is a region ("Europe", "Australia and Oceania" etc.) and the value is the total profit for that region.
The output should look like this:
{'Central America and the Caribbean': 40988504.32, 'Europe': 85933409.37, 'Asia': 64738894.81, 'Middle East and North Africa': 49885092.50, 'Australia and Oceania': 36740921.27, 'Sub-Saharan Africa': 102699264.75, 'North America': 9457684.50}
1 & 2) You may use a list comprehension or a loop to generate the result.
3 ) You may use a list comprehension or a loop + conditional here.
4 ) You might be able to use a comprehension here, but it will be much easier to use a loop. Think about how you will track the order with the highest profit throughout the loop.
Extension: You can check if a key exists within a dictionary by using the in
keyword. For example:
profits = {}
if "Europe" in profits:
# This code will execute if profits["Europe"] exists already
else:
# This code will execute if profits doesn't have a key of Europe yet