Python for Finance (pandas, yfinance, numpy)
Intuition
Python has become the dominant language for quantitative finance, data analysis, and financial automation. Where Excel reaches its limits, with large datasets, repetitive tasks, complex statistical analysis, or automated data pipelines, Python excels. A financial analyst who can write Python code can automate hours of manual work, analyse datasets too large for Excel, and build reproducible research workflows.
You don't need to be a software engineer to use Python productively in finance. A working knowledge of three libraries, pandas for data manipulation, numpy for mathematical operations, and matplotlib/seaborn for visualisation, plus the ability to fetch data from APIs or read from files, is sufficient for most financial analysis tasks.
For Indian markets, the yfinance library provides easy access to NSE price data, and SEBI/exchange APIs provide corporate filing data. Python skills dramatically increase the scope of analysis possible within a given time budget.
Mechanics
Core libraries:
pandas: Data structures (DataFrame, Series) for structured data:
import pandas as pd
df = pd.read_csv('results.csv', parse_dates=['date'])
df['revenue_growth'] = df['revenue'].pct_change()
df.groupby('sector')['ebitda_margin'].mean()
numpy: Numerical operations:
import numpy as np
npv = np.npv(0.12, [-1000, 300, 400, 500, 400]) # Net Present Value
irr = np.irr([-1000, 300, 400, 500, 400]) # IRR
yfinance: Price and fundamental data:
import yfinance as yf
reliance = yf.Ticker("RELIANCE.NS")
history = reliance.history(period="5y")
info = reliance.info # P/E, market cap, sector
matplotlib / seaborn: Visualisation:
import matplotlib.pyplot as plt
df['revenue'].plot(kind='bar', title='Revenue Trend')
plt.tight_layout()
plt.savefig('revenue_chart.png')
Useful for finance:
- Downloading multi-year price history and computing returns
- Screener scraping with requests/BeautifulSoup (check ToS)
- Building discounted cash flow calculators
- Regression analysis (statsmodels, scikit-learn)
- Portfolio optimisation (scipy.optimize)
From the research
How The Valuation Node Approaches Research
The research method behind The Valuation Node, how assumptions are stated, how sources are chosen, and how uncertainty is disclosed in every published analysis.
ValuationWhat Three Years of a Cash Flow Statement Reveals That One Year Hides
A single year of cash flow is a snapshot. Three years is a story. Learn what the trend reveals about earnings quality, funding, and sustainability.
ValuationComparing Two Companies on ROE, and Why the Higher One Is Not Always Better
Two companies can report the same ROE for very different reasons. DuPont analysis shows why an ROE built on leverage is not the same as one built on quality.
Try it yourself
Interactive exercises coming soon.
Related topics
Stay in the loop
Roughly one email per month. No spam, no upsells.