In [ ]:
# Step 1: Include NumPy and create a DataFrame for iPhone Sales Data
import pandas as pd
import matplotlib.pyplot as plt
import numpy as np
from tabulate import tabulate
# Initialize NumPy arrays for sales data
units_sold = np.array([37, 34, 18, 32, 28, 20, 22, 10, 30, 46])
# Create DataFrames for iPhones and regional sales
iphone_data = pd.DataFrame({
    'Model': ['iPhone 11', 'iPhone 12', 'iPhone 12 Pro', 'iPhone 13', 'iPhone 13 Pro', 'iPhone 14', 'iPhone 14 Pro', 'iPhone SE', 'iPhone X', 'iPhone XR'],
    'Release Year': [2019, 2020, 2020, 2021, 2021, 2022, 2022, 2022, 2017, 2018],
    'Base Price': [699, 799, 999, 799, 1100, 799, 1450, 429, 730, 749],
    'Units Sold (millions)': units_sold
})
# DataFrame for regional sales data
region_sales = pd.DataFrame({
    'Model': ['iPhone 11', 'iPhone 12', 'iPhone 13', 'iPhone 14', 'iPhone SE'],
    'North America': [15, 12, 13, 9, 4],
    'Europe': [10, 9, 10, 6, 3],
    'Asia': [12, 13, 9, 5, 3]
})
print(tabulate(iphone_data, headers='keys', tablefmt='pretty'))
print(tabulate(region_sales, headers='keys', tablefmt='pretty'))
+---+---------------+--------------+------------+-----------------------+
|   |     Model     | Release Year | Base Price | Units Sold (millions) |
+---+---------------+--------------+------------+-----------------------+
| 0 |   iPhone 11   |     2019     |    699     |          37           |
| 1 |   iPhone 12   |     2020     |    799     |          34           |
| 2 | iPhone 12 Pro |     2020     |    999     |          18           |
| 3 |   iPhone 13   |     2021     |    799     |          32           |
| 4 | iPhone 13 Pro |     2021     |    1100    |          28           |
| 5 |   iPhone 14   |     2022     |    799     |          20           |
| 6 | iPhone 14 Pro |     2022     |    1450    |          22           |
| 7 |   iPhone SE   |     2022     |    429     |          10           |
| 8 |   iPhone X    |     2017     |    730     |          30           |
| 9 |   iPhone XR   |     2018     |    749     |          46           |
+---+---------------+--------------+------------+-----------------------+
+---+-----------+---------------+--------+------+
|   |   Model   | North America | Europe | Asia |
+---+-----------+---------------+--------+------+
| 0 | iPhone 11 |      15       |   10   |  12  |
| 1 | iPhone 12 |      12       |   9    |  13  |
| 2 | iPhone 13 |      13       |   10   |  9   |
| 3 | iPhone 14 |       9       |   6    |  5   |
| 4 | iPhone SE |       4       |   3    |  3   |
+---+-----------+---------------+--------+------+
In [ ]:
# Step 2: Analyze Data by Region
# Aggregate regional sales
total_sales_by_region = region_sales.set_index('Model').sum(axis=1)
total_sales_by_region_df = total_sales_by_region.to_frame()
print("Total sales by region for selected models:")
print(tabulate(total_sales_by_region_df, headers='keys', tablefmt='pretty'))
# Plot regional sales
region_sales.set_index('Model').plot(kind='bar', stacked=True)
plt.title('Regional iPhone Sales')
plt.xlabel('iPhone Model')
plt.ylabel('Units Sold (millions)')
plt.show()
Total sales by region for selected models:
+-----------+----+
|   Model   | 0  |
+-----------+----+
| iPhone 11 | 37 |
| iPhone 12 | 34 |
| iPhone 13 | 32 |
| iPhone 14 | 20 |
| iPhone SE | 10 |
+-----------+----+
No description has been provided for this image
In [ ]:
# Step 3: Advanced Pricing and Discount Calculations
class iPhonePricing:
    def __init__(self, model, base_price):
        self.model = model
        self.base_price = base_price
    def calculate_discounted_price(self, discount_percentage):
        return self.base_price * (1 - discount_percentage / 100)
    def price_after_tax(self, price, tax_rate):
        return price * (1 + tax_rate / 100)
# Example usage
x = iPhonePricing('iPhone 12 Pro', 999)
y = iPhonePricing('iPhone 13 Pro', 1100)
z = iPhonePricing('iPhone 14 Pro', 1450)
x_discount_price = x.calculate_discounted_price(15)
y_discount_price = y.calculate_discounted_price(15)
z_discount_price = z.calculate_discounted_price(15)
x_final_price = x.price_after_tax(x_discount_price, 8)
y_final_price = y.price_after_tax(y_discount_price, 8)
z_final_price = z.price_after_tax(z_discount_price, 8)
print(f"Final price for {x.model} after discount and tax: ${x_final_price:.2f}")
print(f"Final price for {y.model} after discount and tax: ${y_final_price:.2f}")
print(f"Final price for {z.model} after discount and tax: ${z_final_price:.2f}")
Final price for iPhone 12 Pro after discount and tax: $917.08
Final price for iPhone 13 Pro after discount and tax: $1009.80
Final price for iPhone 14 Pro after discount and tax: $1331.10