Why Pandas When You Have Excel: 5 Years of Apple in 5 Lines | Pandas for Finance Ep1
0views
C
CelesteAI
Description
Episode 1 of *Pandas for Finance*. The bridge from Excel and SQL to Python's data toolkit.
If you finished *Excel & Power BI for Finance* or *SQL for Finance*, you can already build dashboards and run queries. Pandas is the next mile — the Python library every data person uses to read, transform, and analyse market data. The first script is five lines, and it loads five years of Apple price history straight from Yahoo Finance.
What You'll Build:
- A working Python virtualenv with `pandas`, `yfinance`, and `pyarrow` installed in three pip commands.
- A 5-line `first.py` script that downloads AAPL from 2020 to 2025 and prints the head and shape — 1,258 rows of OHLCV data.
- A first feel for the DataFrame: a date-indexed table with named columns (Open, High, Low, Close, Adj Close, Volume) — the pandas equivalent of an Excel sheet.
- Display tweaks (`pd.set_option`) for clean float formatting, plus the first column-stat methods (`.max()`, `.min()`, `.mean()`, `.idxmax()`).
Timestamps:
0:00 - Intro — Pandas for Finance starts here
0:12 - Preview — what's in the next five lines
0:44 - Install pandas, yfinance, pyarrow
1:00 - Write first.py in nvim
1:28 - yf.download is the workhorse
1:58 - Save, cat, run
2:16 - Five years of Apple bars
2:36 - Recap — the three things
3:08 - End screen
Key Takeaways:
1. Three pip installs and you are a finance Python person. `pandas` for the DataFrame, `yfinance` for the data, `pyarrow` for the parquet caching that arrives next episode. No accounts, no API keys, no Yahoo logins — the script runs out of the box from a fresh virtualenv. The whole "set up a data pipeline" problem most analysts hit on day one disappears here.
2. `yf.download(ticker, start, end)` returns a DataFrame and that is the entire mental model. The DataFrame is named `df` by convention; it has a Date index, six named columns (Open, High, Low, Close, Adj Close, Volume), and one row per trading day. If you can picture an Excel sheet with the dates as the leftmost column and the rest of the columns as price data, you've already got the right picture in your head.
3. `.head()` and `.shape` are the first two methods you'll use ten thousand times. `.head()` shows the top five rows so you can sanity-check the data. `.shape` returns `(rows, cols)` so you can confirm you got what you expected. The whole "did the download work" question is answered in two prints.
4. Scripts beat notebooks for finance work. Notebooks are great for exploration, but scripts are easier to version (git diffs work), easier to schedule (cron, GitHub Actions, Airflow), and easier to share with the rest of the team. Every script in this series is a single `.py` file you can drop into any pipeline.
5. Real market data from line one. We're not using a teaching toy — Apple bars from 2020 to 2025, straight from Yahoo Finance. The 14 episodes that follow each add one finance-shaped skill: filtering, returns, groupby, joins, dates, rolling windows, cleaning, and a final 14-episode backtest. By the end you'll be writing a Monday-morning analyst script: download, clean, aggregate, save to Excel.
#Pandas #Python #Finance #DataAnalytics #Yfinance #DataFrame #FinancialReporting #PythonForFinance #LearnPython #PandasForFinance