σμimplied vol · KKmax(S−K,0)udβρᵢⱼfat tailsPnL · drawdownyield · TdSₜ = μSₜ dt + σSₜ dWₜC = S·N(d₁) − K·e⁻ʳᵀ·N(d₂)σₚ² = wᵀΣwd₁ = [ln(S/K) + (r + σ²⁄2)T] ⁄ σ√T∂V/∂t + ½σ²S²·∂²V/∂S² + rS·∂V/∂S − rV = 0Sharpe = (Rₚ − R_f) ⁄ σₚVaR₉₉ = μ − 2.33σρ = Cov(X,Y) ⁄ σₓσᵧE[Rₚ] = Σ wᵢ·E[Rᵢ]φ(x) = e^(−x²/2) ⁄ √2πE[Rᵢ] = R_f + βᵢ(E[Rₘ] − R_f)dXₜ = θ(μ − Xₜ)dt + σ dWₜσ²ₜ = ω + α·ε²ₜ₋₁ + β·σ²ₜ₋₁C − P = S − K·e⁻ʳᵀΔ = ∂V/∂S Γ = ∂²V/∂S²p = (e^(rΔt) − d) ⁄ (u − d)rₜ = ln(Pₜ ⁄ Pₜ₋₁)E[Xₜ₊₁ | ℱₜ] = Xₜf* = (bp − q) ⁄ bz = (x − μ) ⁄ σP(N=k) = λᵏe^(−λ) ⁄ k!Θ = −∂V/∂Tν = S·φ(d₁)·√Tmin wᵀΣw s.t. wᵀμ = μ*∫Σ∂∞λ
uantCraft AcademyRoadmapsSkills
Ctrl K
AO
+1.2k Learners
LoginJoin ↗
RoadmapsSkills
AO
+1.2k Learners
Login
  • English
  • Français
  • Español
  • العربية
  • Português
  • Deutsch
  • 日本語
  • 中文
σμimplied vol · KKmax(S−K,0)udβρᵢⱼfat tailsPnL · drawdownyield · TdSₜ = μSₜ dt + σSₜ dWₜC = S·N(d₁) − K·e⁻ʳᵀ·N(d₂)σₚ² = wᵀΣwd₁ = [ln(S/K) + (r + σ²⁄2)T] ⁄ σ√T∂V/∂t + ½σ²S²·∂²V/∂S² + rS·∂V/∂S − rV = 0Sharpe = (Rₚ − R_f) ⁄ σₚVaR₉₉ = μ − 2.33σρ = Cov(X,Y) ⁄ σₓσᵧE[Rₚ] = Σ wᵢ·E[Rᵢ]φ(x) = e^(−x²/2) ⁄ √2πE[Rᵢ] = R_f + βᵢ(E[Rₘ] − R_f)dXₜ = θ(μ − Xₜ)dt + σ dWₜσ²ₜ = ω + α·ε²ₜ₋₁ + β·σ²ₜ₋₁C − P = S − K·e⁻ʳᵀΔ = ∂V/∂S Γ = ∂²V/∂S²p = (e^(rΔt) − d) ⁄ (u − d)rₜ = ln(Pₜ ⁄ Pₜ₋₁)E[Xₜ₊₁ | ℱₜ] = Xₜf* = (bp − q) ⁄ bz = (x − μ) ⁄ σP(N=k) = λᵏe^(−λ) ⁄ k!Θ = −∂V/∂Tν = S·φ(d₁)·√Tmin wᵀΣw s.t. wᵀμ = μ*∫Σ∂∞λ
uantCraft AcademyRoadmapsSkills
Ctrl K
AO
+1.2k Learners
LoginJoin ↗
RoadmapsSkills
AO
+1.2k Learners
Login
  • English
  • Français
  • Español
  • العربية
  • Português
  • Deutsch
  • 日本語
  • 中文
Parquet skill›Module 1 · Inside the file›Topic 1.1·~40 minIntermediate

Row versus columnar storage

Skill positionModule 1 of 3 · Topic 1 of 3
1.1 Row versus columnar storage
—Lab score— / 100Total XP—Streak—
Lecture0% read

3 min readCode examples: 3

  1. 01The idea in plain words
  2. 02Same table, two files
  3. 03Read only what you need
  4. 04What the tasks ask

Ask a CSV file for the closing price of one stock and it reads every byte of every column of every row. Ask a Parquet file for the same thing and it reads the bytes of one column. That single difference, storing a table by column instead of by row, is why research data lives in Parquet.

01

The idea in plain words

Where we are. The first topic of the Parquet skill. It builds on the DuckDB skill, where Parquet was just a source to query, and opens the file itself. The next topics look inside it (row groups, pages, codecs) and then use that layout to read less.

DefinitionColumnar storage

Storing a table one column after another instead of one record after another. A query that needs two columns reads two columns, and because each column holds one kind of value, it compresses far better than rows of mixed values.

02

Same table, two files

load_bars() returns the daily bars of five stocks as an Arrow table of about 33,000 rows. pyarrow.csv.write_csv and pyarrow.parquet.write_table write it both ways. The Parquet file is already smaller, and that is with the default settings, before any tuning.

main.pyPython
# Write the table as CSV and as Parquet, then compare the two filesprint(table.num_rows, "rows;", table.column_names)csv_bytes, parquet_bytes = file_sizes(table, ".")print("csv bytes:", csv_bytes)print("parquet bytes:", parquet_bytes)print("csv is", round(csv_bytes / parquet_bytes, 2), "times bigger")
33493 rows; ['symbol', 'date', 'open', 'high', 'low', 'close', 'volume']
csv bytes: 1914722
parquet bytes: 1246066
csv is 1.54 times bigger
03

Read only what you need

The size win is real, the speed win is bigger. A Parquet file ends with a footer that records where every column's bytes start and how many there are. read_columns asks for two columns and the reader jumps straight to them. column_bytes reads only that footer to tell you what the jump costs, without touching the data.

main.pyPython
# Read two columns, then ask the footer how much of the file they taketwo = read_columns("bars.parquet", ["date", "close"])print(two.column_names, two.num_rows)asked = column_bytes("bars.parquet", ["date", "close"])whole = column_bytes("bars.parquet", table.column_names)print("bytes for date + close:", asked, "of", whole)print("share of the file:", f"{asked / whole:.0%}")
['date', 'close'] 33493
bytes for date + close: 311253 of 1244525
share of the file: 25%
main.pyPython
# Which single column is the heaviest in the file?for name in table.column_names:    print(name, column_bytes("bars.parquet", [name]))print("widest:", widest_column("bars.parquet"))
symbol 161
date 81455
open 226085
high 226308
low 230269
close 229798
volume 250449
widest: ('volume', 250449)
Wide tables favour Parquet most

This table has seven columns and a query usually wants two or three. A feature table with two hundred columns and a model that uses ten is where columnar storage turns a minutes-long read into seconds. Keep wide tables in Parquet and ask for columns by name.

04

What the tasks ask

  1. 1
    `file_sizes`Write bars.csv with pacsv.write_csv and bars.parquet with pq.write_table; return both sizes from os.path.getsize.
  2. 2
    `read_columns`pq.read_table(path, columns=...): the reader fetches only those columns.
  3. 3
    `column_bytes`Loop the row groups of pq.ParquetFile(path).metadata and add total_compressed_size of the wanted column chunks.
  4. 4
    `widest_column`Measure each column with column_bytes and return the largest as (name, bytes); a tie goes to the first.

Key takeaways

  • Columns are stored apart A query reads only the columns it names.
  • The footer tells you before you read Sizes and layout are metadata, so you can plan a read without making it.
  • Smaller and faster Same data, fewer bytes on disk and fewer read. Next: what is inside the file.
Quick check
A query needs date and close from a Parquet file with seven columns. Roughly how much of the file does a good reader fetch?
Pick an answer.

Lab · what's graded

4 tasks · 100 pts
  • Write it both ways: file_sizes25 pts
  • Read only the columns you need: read_columns25 pts
  • Count bytes from the footer: column_bytes25 pts
  • Find the widest column: widest_column25 pts
Explorer · lab-1-1
▾ lab-1-1
▾ data
…
bash · in-browser
learner@quantcraft:~/lab-1-1$
Python not loaded yetPythonLn 1, Col 1Spaces: 4UTF-8

Reset this topic?

Everything in lab-1-1 goes back to the starter files and the terminal is cleared. Your current solution will be lost — this can't be undone.

Will be reset
  • main.py → starter code
  • Terminal history and test output
  • Unsubmitted changes
Will be kept
  • Best lab score
  • Your XP and streak
  • Lecture progress and notes