Python in Business: Probability,
Financial Fundamentals, and
Data Analysis
Dr. Saima Nisar
PhD (IT), MS (IT), BBA (Hons.)
Learning Objectives:
By the end of this lecture, students will be able to:
Understand the role and advantages of Python in business
analytics.
Apply probability concepts in Python to simulate real-world
business scenarios.
Calculate future and present values for investment planning.
Visualize business data effectively with 2D and 3D graphs in
Python.
Introduction to Python in Business
• Python’s Role in Business: Python is a powerful tool for
analyzing and interpreting data in business and statistics,
providing valuable insights and predictions.
• Why Python?: Its efficiency, flexibility, and ease of use make
it ideal for handling data, performing calculations, and
generating graphs.
• Key Libraries: NumPy for mathematical operations, Pandas
for data manipulation, Matplotlib for visualizations, and SciPy
for statistics.
Probability in Business
• Probability is the measure of how likely it is that a
particular event will occur.
• In business, probability helps us to make decisions
under uncertain events, like predicting the likelihood
of a product's success or market trends.
• We use Python’s NumPy library to simulate
probability-based scenarios, like rolling a die to see
how often each face appears.
Probability in Business
Example:
• Simulating (pretend) a die roll to understand random outcomes.
• Simulating multiple trials gives a broader view of probability. In
business, this could relate to repeated customer purchases or
recurring transactions.
import numpy as np
# Simulate rolling a die
print("Rolling a die once:",[Link](1, 7))
# Roll a die 10 times
few_rolls = [Link](1, 7, size=10)
print("Rolling a die 10 times:", few_rolls)
Coin Flips and Binomial Distribution
Binomial Distribution represents the number of successes in a
fixed number of trials. In business, it’s used in quality control
(e.g., defective items in a batch)
• Using the SciPy library to simulate coin flips as a binomial
distribution.
from [Link] import binom
# Simulate a binomial distribution of 10 coin flips
n_flips = 10
p_success = 0.5 # 50% chance of heads
distribution = [Link](range(n_flips + 1), n_flips, p_success)
[Link](range(n_flips + 1), distribution)
[Link]("Number of Heads")
[Link]("Probability")
[Link]()
Demand Forecasting Simulation
• Demand forecasting means predicting how many customers will buy
a product in the future. This is crucial for businesses to avoid
overstocking or running out of products.
• Predict demand over 30 days using random values.
• Visualize demand with a histogram to understand frequency.
demand = [Link](20, 100, size=30)
import [Link] as plt
%matplotlib inline
[Link](demand, bins=10, edgecolor='black')
[Link]("Simulated Demand over 30 Days")
[Link]("Demand")
[Link]("Frequency")
[Link]()
Future & Present Values
Time Value of Money: Money now is more valuable than the same
amount in the future, due to potential interest or investment returns.
Future Value (FV) answers the question, “If I invest money now,
how much will it be worth in the future?”
Future Value (FV): The growth of an investment over time
Future Value Calculation in Python
• Calculate how an investment grows over time.
• Example: Investment of $1,000 at 10% for 10 years.
investment = 1000
interest_rate = 0.1
years = 10
future_value = (1 + interest_rate) ** years * investment
print(f"Future Value after {years} years: ${future_value:.2f}")
Present Values
Present Value (PV) tells us the worth of future cash flows
today, aiding in investment decisions.
Example in Business: Helps companies evaluate the
feasibility of projects by comparing the current worth of
future cash flows.
Present Value (PV): Today’s worth of a
future amount.
Present Value Calculation in Python
• Determine today’s worth of a future amount.
• Example: Calculate PV of the investment’s future worth.
present_value = future_value / (1 + interest_rate) ** years
print(f"Present Value of ${future_value:.2f} in {years} years: ${present_value:.2f}")
Present Value and Discounting Cash Flows
• Example in Business: Helps companies evaluate the
feasibility of projects by comparing the current worth of future
cash flows..
future_cash = 2593.74
years = 10
discount_rate = 0.05
present_value = future_cash / (1 + discount_rate)**years
print("Present Value:", present_value)
Three Dimensional Graphs
• 3D Graphing: 3D graphs allow visualization across multiple
variables. In business, we can plot factors like sales volume
vs. product type vs. customer segment.
• Use Matplotlib's 3D plotting features to visualize relationships
between multiple variable
from mpl_toolkits.mplot3d import Axes3D
fig = [Link]()
ax = fig.add_subplot(111, projection='3d')
people = [Link](1, 11)
rootbeers = [Link](0, 20)
people, rootbeers = [Link](people, rootbeers)
total_cost = 80 * people + 10 * rootbeers + 40
ax.plot_surface(people, rootbeers, total_cost)
ax.set_xlabel("People")
ax.set_ylabel("Rootbeers")
ax.set_zlabel("Total Cost")
[Link]()
Data Visualization and High-Quality Graphing Techniques
Data visualization and high-quality graphing techniques are
essential in business analytics. They transform raw data into
visual representations, making complex data sets easier to
interpret, analyze, and communicate.
High-quality visuals reduce the chances of misinterpretation.
Businesses use data visualizations to make data-driven
decisions.
Example: Sales trends, customer segmentation, and
forecasting models are all represented in charts or graphs.
Data Visualization and High-Quality Graphing
Techniques
import [Link] as plt
years = [Link](0, 10, 100)
interest_rates = [0, 5, 10, 15, 20]
for rate in interest_rates:
investment = (1 + rate/100) ** years
[Link](years, investment, label=f'Rate: {rate}%')
[Link]("Years")
[Link]("Investment Value")
[Link]()
[Link](True)
[Link]("Investment Growth over Time")
[Link]()
Thank you