The fast food industry represents one of the most dynamic sectors in the stock market, with companies ranging from global giants like McDonald's to innovative newcomers like Luckin Coffee. In this project, you'll create an interactive line chart to visualize historical stock prices for 10 major fast-food companies. Building interactive dashboards is a critical skill in modern business, as these tools help analysts, portfolio managers, and executives make informed, data-driven decisions.
Dataset Summary
Your primary dataset, companies.csv, contains historical stock market data from Yahoo Finance. This dataset captures daily trading activity from major players across the fast food sector. It includes stock data from these industry leaders:
| Ticker | Company | Description |
|---|---|---|
| BRK-A | Berkshire Hathaway Inc. | Financial conglomerate with major fast food investments |
| DNUT | Krispy Kreme, Inc. | Specialty donut and coffee retailer |
| DPZ | Domino's Pizza, Inc. | Global pizza delivery leader |
| LKNCY | Luckin Coffee Inc. | Chinese coffee chain competitor |
| MCD | McDonald's Corporation | World's largest fast food restaurant chain |
| PZZA | Papa John's International | Pizza delivery and takeout specialist |
| QSR | Restaurant Brands International | Parent of Burger King, Tim Hortons, and Popeyes |
| SBUX | Starbucks Corporation | Global coffeehouse chain |
| WEN | The Wendy's Company | Premium burger restaurant chain |
| YUM | Yum! Brands, Inc. | Parent of KFC, Taco Bell, and Pizza Hut |
Note: A ticker is a unique stock symbol used to identify companies on exchanges (e.g., "MCD" for McDonald's, "SBUX" for Starbucks).
Data Structure
companies.csv
| Column | Description |
|---|---|
date | Trading date |
open | Opening price for the trading session |
high | Highest price during the day |
low | Lowest price during the day |
close | Closing price at market close |
adj_close | Price adjusted for dividends and stock splits |
volume | Number of shares traded |
company_ticker | Company stock symbol identifier |
import pandas as pd
import plotly.express as px
import plotly.graph_objects as go
# Read the CSV file
companies = pd.read_csv('companies.csv')
# Ensure 'date' is in datetime format
companies['date'] = pd.to_datetime(companies['date'])
companies.head()# Start coding here. Use as many cells as you like!
import pandas as pd
import plotly.graph_objects as go
import plotly.express as px
# Load the dataset
df = pd.read_csv('companies.csv', parse_dates=['date'])
# tickers, column mapping
tickers = ['BRK-A', 'DNUT', 'DPZ', 'LKNCY', 'MCD', 'PZZA', 'QSR', 'SBUX', 'WEN', 'YUM']
col_map = {'open': 'Opening Price',
'high': 'Highest Price',
'low': 'Lowest Price',
'close': 'Closing Price',
'adj_close': 'Adjusted Closing Price',
'volume': 'Volume'}
default_ticker = 'MCD'
default_col = 'close'
# Create figure
fig = go.Figure()
for ticker in tickers:
company_df = df[df['company_ticker'] == ticker]
visible = True if ticker == default_ticker else 'legendonly'
fig.add_trace(
go.Scatter(
x=company_df['date'],
y=company_df[default_col],
mode='lines',
name=ticker,
visible=(ticker == default_ticker)))
# Company buttons
company_buttons = []
for i, ticker in enumerate(tickers):
visibility = [j == i for j in range(len(tickers))]
button = dict(
label=ticker,
method='update',
args=[{'visible': visibility},
{'title': f"{ticker} Stock Prices"}])
company_buttons.append(button)
# Column (price) buttons
column_buttons = []
for col, label in col_map.items():
y_lists = [
df[df['company_ticker'] == ticker][col].values
for ticker in tickers]
button = dict(
label=label,
method='restyle',
args=[{'y': y_lists}])
column_buttons.append(button)
# Time range selector
range_buttons = list([
dict(count=1, label="1M", step="month", stepmode="backward"),
dict(count=6, label="6M", step="month", stepmode="backward"),
dict(count=1, label="1Y", step="year", stepmode="backward"),
dict(count=3, label="3Y", step="year", stepmode="backward")])
# Update layout
fig.update_layout(
title=f"{default_ticker} Stock Prices",
xaxis=dict(
title='Date',
rangeselector=dict(
buttons=range_buttons),
rangeslider=dict(visible=True),
type='date'),
yaxis=dict(title=col_map[default_col]),
updatemenus=[
dict(
buttons=company_buttons,
direction="down",
showactive=True,
x=0.0,
xanchor="left",
y=1.2,
yanchor="top"),
dict(
buttons=column_buttons,
direction="down",
showactive=True,
x=0.3,
xanchor="left",
y=1.2,
yanchor="top")],
legend_title="Company",
hovermode='x unified')
# Show the figure
fig.show()