A DataFrame is a tabular structure with labeled rows and columns that can hold different value types. Financial workflows use it to store accounting statements, portfolio positions, ratios, and merged market data. section 3.4.1 section 6.3
Common operations include:
- Retrieve income statements, balance sheets, and cash-flow statements, with reporting dates as columns and metrics as rows. section 3.4.1
- Select a dated metric such as EBITDA, access quarterly statements, and convert dictionary-like company information into a Pandas Series. section 3.4.1
- Merge external company metrics into portfolio positions, standardize currencies, calculate aggregate values, and export results to a spreadsheet. section 6.5.1 section 6.3
Microsoft accounting data
Create a yfinance Ticker for MSFT and inspect microsoft.income_stmt. The resulting DataFrame places reporting dates such as 2024-06-30 in columns and measures such as EBITDA in rows; a specific value can be selected by date and metric. section 3.4.1
Listing 6.4 Merging Yahoo Finance data into DataFrames
def merge_fin_data (df_orig, ticker_data, metrics):
df = df_orig.copy(deep=True)
for m in metrics:
df[m] = None
for ind in df.index:
ticker_symbol = df.loc[ind, "yahoo"] #1
company = ticker_data.get(ticker_symbol, {}) #1
for m in metrics: #2
df.loc[ind, m] = company.get(m, None) #2
return df
ratios = ["currentPrice", "targetMeanPrice", "dividendRate"]
stocks = merge_fin_data(shares, yfin_data_stocks, ratios)
Inspect a merge function that copies a portfolio DataFrame, adds requested metric columns, matches ticker symbols, and fills missing values with None. section 6.5.1


















