import pandas as pd
import vizro.models as vm
import vizro.plotly.express as px
from vizro import Vizro
dash = pd.read_csv("dashboard_data.csv")
cost_2025 = dash[(dash["ticker"] == "COST") & (dash["fiscal_year"] == 2025)]
wmt_2025 = dash[(dash["ticker"] == "WMT") & (dash["fiscal_year"] == 2025)]
tgt_2025 = dash[(dash["ticker"] == "TGT") & (dash["fiscal_year"] == 2025)]
costco = dash[(dash["ticker"] == "COST") & (dash["fiscal_year"] <= 2017)]
no_year = {"fiscal_year": ""}
overview = vm.Page(
title="Overview",
components=[
vm.Card(text=f"Costco P/E (2025)\n\n# {cost_2025['P/E'].iloc[0]:.1f}x"),
vm.Card(text=f"Walmart P/E (2025)\n\n# {wmt_2025['P/E'].iloc[0]:.1f}x"),
vm.Card(text=f"Target P/E (2025)\n\n# {tgt_2025['P/E'].iloc[0]:.1f}x"),
vm.Graph(title="Revenue growth (2010 = 100)", figure=px.line(dash, x="fiscal_year", y="Revenue Index", color="ticker", markers=True, labels=no_year)),
vm.Graph(title="Net income ($ billions)", figure=px.line(dash, x="fiscal_year", y="Net Income ($B)", color="ticker", markers=True, labels=no_year)),
],
layout=vm.Grid(grid=[[0, 0, 1, 1, 2, 2],
[3, 3, 3, 4, 4, 4],
[3, 3, 3, 4, 4, 4],
[3, 3, 3, 4, 4, 4]]),
)
investors = vm.Page(
title="Investors",
components=[
vm.Graph(title="Return on equity", figure=px.line(dash, x="fiscal_year", y="Return on Equity", color="ticker", markers=True, labels=no_year)),
vm.Graph(title="Net margin", figure=px.line(dash, x="fiscal_year", y="Net Margin", color="ticker", markers=True, labels=no_year)),
vm.Graph(title="P/E ratio", figure=px.line(dash, x="fiscal_year", y="P/E", color="ticker", markers=True, labels=no_year)),
vm.Graph(title="Stock price growth (2010 = 100)", figure=px.line(dash, x="fiscal_year", y="Stock Price Index", color="ticker", markers=True, labels=no_year)),
],
layout=vm.Grid(grid=[[0, 1], [2, 3]]),
controls=[vm.Filter(column="ticker"), vm.Filter(column="fiscal_year")],
)
lenders = vm.Page(
title="Lenders & Regulators",
components=[
vm.Graph(title="Current ratio", figure=px.line(dash, x="fiscal_year", y="Current Ratio", color="ticker", markers=True, labels=no_year)),
vm.Graph(title="Liabilities-to-equity", figure=px.line(dash, x="fiscal_year", y="Liabilities-to-Equity", color="ticker", markers=True, labels=no_year)),
vm.Graph(title="Interest coverage", figure=px.line(dash, x="fiscal_year", y="Interest Coverage", color="ticker", markers=True, labels=no_year)),
vm.Graph(title="Free cash flow ($ billions)", figure=px.bar(dash, x="fiscal_year", y="Free Cash Flow", color="ticker", barmode="group", labels=no_year)),
],
layout=vm.Grid(grid=[[0, 1], [2, 3]]),
controls=[vm.Filter(column="ticker"), vm.Filter(column="fiscal_year")],
)
membership = vm.Page(
title="Costco Membership",
components=[
vm.Graph(title="Membership fees as % of operating income (2010-2017)", figure=px.bar(costco, x="fiscal_year", y="Fees % of Operating Income", labels=no_year)),
],
)
memo_page = vm.Page(
title="Memo",
components=[
vm.Card(text="""
Costco has delivered the strongest growth of the three retailers over the years 2010-2025. Its revenue increased 3.5 times its 2010 revenue and net income increased 6.2 times. Earnings grew roughly twice as fast as sales with net margin going from 1.7% to 2.9%. Membership fees contribute to Costco's low price model with the fees covering 81% of operating income in 2010 and 69% in 2017. Walmart has been a steady performer, growing revenue to 1.7 times and net income to 1.33 times its 2010 base with only two isolated declines. Target has been the most volatile. It had unusual increases in 2020-2021 with net income increase of 59% in 2021 followed by a reversal of negative 60% in 2022.
Target earns the highest gross margin at 29% while Costco has the lowest gross margin at 13%. Operational costs for each company vary and they all end up with 2 to 4 cents of profit per dollar of sales. Costco has a high inventory turnover with 22% ROE. Target has the highest ROE of 24.3% due to the highest margins but it has the lowest asset and inventory turnover and increased leverage. Walmart is in the middle on margin with the lowest ROE at 18.6%.
Costco's profit per share grew 6 times while its stock price grew 17 times and Walmart's EPS barely doubled against the share price increasing 6 times, showing investors pay for more reliable stocks. Target's share price is parallel to its profit growth. By 2025 investors paid 52 times earnings for Costco and 41 for Walmart, but only 12 for Target. Costco keeps 16% of its assets in cash, much more than Walmart and Target. The cash is a safety net but it is worth questioning whether the money could be invested further or returned to shareholders.
""", extra={"style": {"fontSize": "18px"}}),
],
)
dashboard = vm.Dashboard(
pages=[overview, investors, lenders, membership, memo_page],
title="Walmart vs. Target vs. Costco, 2010-2025",
navigation=vm.Navigation(nav_selector=vm.NavBar(position="top")),
)
Vizro().build(dashboard).run()