liveBook · Manning

Data frame

As explained in Investing for Programmers

A DataFrame is a tabular data structure organized into labeled rows and columns that may contain values of different types.

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

How Investing for Programmers covers it

How deep it goes
Explains labeled rows and columns, selection, merging, conversion, and aggregation, but does not detail DataFrame internals.
Examples
Demonstrates Microsoft statements, quarterly statements, portfolio positions, ticker-based metric merges, currency conversion, and aggregate investment values.
What it assumes
Assumes familiarity with Python objects, attributes, indexing, and financial identifiers such as tickers and accounting metrics.
What you can do after
Build it from scratch by retrieving financial data, selecting metrics, merging DataFrames, standardizing currencies, and calculating portfolio values.
How it connects
Connects DataFrames with Python, pandas, yfinance, Pandas Series, financial ratios, currency conversion, and spreadsheet export.

Also explained in

Compare how 19 books explain data frame →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Investing for Programmers. The section links point to the parts of the book it draws on.