Created
January 20, 2026 15:23
-
-
Save hodgesmr/e24559c17b979dffa452851373500292 to your computer and use it in GitHub Desktop.
Federal Reserve list of largest commercial banks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import pandas as pd | |
| import matplotlib.pyplot as plt | |
| import requests | |
| from io import StringIO | |
| # Fetch the table from the Federal Reserve page with proper headers | |
| url = "https://www.federalreserve.gov/releases/lbr/current/" | |
| headers = { | |
| "User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36" | |
| } | |
| response = requests.get(url, headers=headers) | |
| response.raise_for_status() | |
| tables = pd.read_html(StringIO(response.text)) | |
| # The main table should be the largest one | |
| df = max(tables, key=len) | |
| # Display columns to understand structure | |
| print("Columns:", df.columns.tolist()) | |
| print("\nFirst few rows:") | |
| print(df.head()) | |
| # Find the assets column (contains "Consol" and "Assets") | |
| assets_col = [ | |
| c for c in df.columns if "consol" in str(c).lower() and "asset" in str(c).lower() | |
| ][0] | |
| name_col = [c for c in df.columns if "name" in str(c).lower()][0] | |
| print(f"\nUsing columns: {name_col}, {assets_col}") | |
| # Clean the data | |
| df_clean = df[[name_col, assets_col]].copy() | |
| df_clean.columns = ["Bank", "Assets"] | |
| # Convert assets to numeric (remove commas if string) | |
| df_clean["Assets"] = pd.to_numeric( | |
| df_clean["Assets"].astype(str).str.replace(",", ""), errors="coerce" | |
| ) | |
| # Get top 10 | |
| top10 = df_clean.nlargest(10, "Assets") | |
| print("\nTop 10 banks by Consolidated Assets:") | |
| print(top10) | |
| # Create the bar chart with nice styling | |
| plt.style.use("seaborn-v0_8-whitegrid") | |
| fig, ax = plt.subplots(figsize=(12, 8)) | |
| # Create horizontal bar chart (easier to read bank names) | |
| colors = plt.cm.Blues([(i + 3) / 13 for i in range(10)])[::-1] | |
| bars = ax.barh( | |
| range(len(top10)), | |
| top10["Assets"].values / 1e6, | |
| color=colors, | |
| edgecolor="navy", | |
| linewidth=0.5, | |
| ) | |
| # Set labels | |
| ax.set_yticks(range(len(top10))) | |
| ax.set_yticklabels(top10["Bank"].values, fontsize=10) | |
| ax.invert_yaxis() # Largest at top | |
| # Format x-axis as trillions | |
| ax.set_xlabel("Consolidated Assets (Trillions $)", fontsize=12, fontweight="bold") | |
| ax.set_title( | |
| "Top 10 Large Commercial Banks by Consolidated Assets\n(Federal Reserve Data, September 2025)", | |
| fontsize=14, | |
| fontweight="bold", | |
| pad=20, | |
| ) | |
| # Add value labels on bars | |
| for i, (bar, val) in enumerate(zip(bars, top10["Assets"].values)): | |
| ax.text( | |
| bar.get_width() + 0.02, | |
| bar.get_y() + bar.get_height() / 2, | |
| f"${val/1e6:.2f}T", | |
| va="center", | |
| fontsize=9, | |
| fontweight="bold", | |
| ) | |
| # Adjust x-axis limit to make room for labels | |
| ax.set_xlim(0, top10["Assets"].max() / 1e6 * 1.15) | |
| # Style tweaks | |
| ax.spines["top"].set_visible(False) | |
| ax.spines["right"].set_visible(False) | |
| ax.tick_params(axis="y", length=0) | |
| plt.tight_layout() | |
| plt.savefig("top10_banks.png", dpi=150, bbox_inches="tight", facecolor="white") | |
| plt.savefig("top10_banks.pdf", bbox_inches="tight", facecolor="white") | |
| print("\nSaved: top10_banks.png and top10_banks.pdf") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment