Skip to content

Instantly share code, notes, and snippets.

@mrdbourke
Created May 5, 2020 03:08
Show Gist options
  • Save mrdbourke/a213d9fcd922a85294cc4a34571bde4a to your computer and use it in GitHub Desktop.
Save mrdbourke/a213d9fcd922a85294cc4a34571bde4a to your computer and use it in GitHub Desktop.
import numpy as np
import pandas as pd
np.random.seed(0)
sales_amounts = np.random.randint(20, size=(5, 3))
weekly_sales = pd.DataFrame(sales_amounts,
index=["Mon", "Tues", "Wed", "Thurs", "Fri"],
columns=["Almond butter", "Peanut butter", "Cashew butter"])
prices = np.array([10, 8, 12])
print(f"Weekly sales shape: {weekly_sales.shape}")
butter_prices = pd.DataFrame(prices.reshape(1, 3),
index=["Price"],
columns=["Almond butter", "Peanut butter", "Cashew butter"])
print(f"Butter prices shape: {butter_prices.shape}")
print(f"Weekly sales shape (transposed): {weekly_sales.T.shape}")
daily_sales = butter_prices.dot(weekly_sales.T)
print(f"Daily sales shape: {daily_sales.shape}")
weekly_sales["Total"] = daily_sales.T
weekly_sales
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment