Kenneth French data in Python

Monthly and daily returns of the Fama-French factors and of portfolios sorted on size, value, industry and other variables, for the US and other regions.
Published

November 25, 2026

Updated

November 29, 2026

Kenneth French’s data library is free and needs no account or key. Its nearly 300 CSV files cover the US, Europe, Japan, the emerging markets and other regions, and each holds one or more tables. Run pip install pandas. The monthly and daily scripts print the file’s notes and table titles and save one table as a long-format CSV in FOLDER (default Downloads). The file name comes from FILE and TITLE, so each table gets its own file, and a rerun overwrites a file of the same name. An empty TITLE takes the first table. Missing values are blank. The example returns are in percent, and other tables can hold firm counts.

If a script does not work as it should, email me.

Find a file

The script lists the file names that contain a word, to copy into FILE in the monthly or daily script.

Choose these settings in the code:

  • WORD, a word in the file names, such as Europe, Japan, Emerging, Daily or Industry, or empty for all files.
import re
import urllib.request

PAGE = "https://mba.tuck.dartmouth.edu/pages/faculty/ken.french/data_library.html"
WORD = "Europe"   # a word in the file names, such as Europe, Japan, Emerging, Daily or Industry ("" lists all)

with urllib.request.urlopen(PAGE, timeout=60) as response:
    page = response.read().decode("latin-1")
files = sorted(set(re.findall(r'ftp/([^"]+_CSV\.zip)', page)))
print("\n".join(name for name in files if WORD.lower() in name.lower()))

Monthly returns

One row per month and portfolio or factor. The example takes the value-weighted returns of the six size and book-to-market portfolios from July 1926.

Choose these settings in the code:

  • FILE, a monthly file. Europe_3_Factors_CSV.zip with an empty TITLE gives the European factors.
  • TITLE, a printed table title. "Average Equal Weighted Returns -- Monthly" gives the equal-weighted returns, and in a factor file, the first table holds the monthly factors.
  • FOLDER, the output folder.
import io
import re
import urllib.request
import zipfile
from itertools import takewhile
from pathlib import Path

import pandas as pd

LIBRARY = "https://mba.tuck.dartmouth.edu/pages/faculty/ken.french/ftp/"
FILE = "6_Portfolios_2x3_CSV.zip"                    # a monthly file, for example Europe_3_Factors_CSV.zip
TITLE = "Average Value Weighted Returns -- Monthly"  # a table title from the printed notes ("" takes the first table)
FOLDER = Path.home() / "Downloads"                   # change this to the folder for the CSV file

# Step 1. Download the ZIP file and print the notes and table titles of its CSV file
with urllib.request.urlopen(LIBRARY + FILE, timeout=60) as response:
    archive = zipfile.ZipFile(io.BytesIO(response.read()))
lines = archive.read(archive.namelist()[0]).decode("latin-1").splitlines()
text = pd.Series(lines).str.strip()
print("\n".join(text[text.ne("") & ~text.str.match(r"[\d,]")]))

# Step 2. The table under TITLE, one row per month
assert any(TITLE in line for line in lines), "TITLE is not in the file. Copy a title from the printed notes."
first = next(number for number, line in enumerate(lines) if TITLE in line)
start = next(number for number in range(first, len(lines)) if lines[number].startswith(","))
rows = list(takewhile(str.strip, lines[start:]))
table = pd.read_csv(io.StringIO("\n".join(rows)), index_col=0)
dates = table.index.astype(str).str.strip()
assert (dates.str.len() == 6).all(), "This table is not monthly. Pick a table with 6-digit dates."
table.index = pd.to_datetime(dates, format="%Y%m").to_period("M")
table.columns = table.columns.str.strip()
table = table.replace([-99.99, -999], float("nan"))

# Step 3. Long format, one row per month and series, saved as one CSV file named after FILE and TITLE
panel = table.rename_axis("date").reset_index().melt(id_vars="date", var_name="series", value_name="value")
name = FILE.removesuffix("_CSV.zip") + "_" + (re.sub(r"\W+", "_", TITLE).strip("_") or "first_table")
FOLDER.mkdir(parents=True, exist_ok=True)
panel.to_csv(FOLDER / f"{name}.csv", index=False)
print(len(panel), "rows saved in", FOLDER / f"{name}.csv")

Full post: How to use Kenneth French’s data library

Daily returns

One row per trading day and portfolio or factor. The example takes the factors Mkt-RF, SMB and HML and the risk-free rate (RF) from 1 July 1926.

Choose these settings in the code:

  • FILE, a daily file, such as 12_Industry_Portfolios_daily_CSV.zip or Europe_3_Factors_Daily_CSV.zip.
  • TITLE, a printed table title, such as "Average Value Weighted Returns -- Daily" for the 12 industries.
  • FOLDER, the output folder.
import io
import re
import urllib.request
import zipfile
from itertools import takewhile
from pathlib import Path

import pandas as pd

LIBRARY = "https://mba.tuck.dartmouth.edu/pages/faculty/ken.french/ftp/"
FILE = "F-F_Research_Data_Factors_daily_CSV.zip"     # a daily file, for example Europe_3_Factors_Daily_CSV.zip
TITLE = ""                                           # a table title from the printed notes ("" takes the first table)
FOLDER = Path.home() / "Downloads"                   # change this to the folder for the CSV file

assert "weekly" not in FILE.lower(), "Pick a daily file. Weekly files also have 8-digit dates."

# Step 1. Download the ZIP file and print the notes and table titles of its CSV file
with urllib.request.urlopen(LIBRARY + FILE, timeout=60) as response:
    archive = zipfile.ZipFile(io.BytesIO(response.read()))
lines = archive.read(archive.namelist()[0]).decode("latin-1").splitlines()
text = pd.Series(lines).str.strip()
print("\n".join(text[text.ne("") & ~text.str.match(r"[\d,]")]))

# Step 2. The table under TITLE, one row per trading day
assert any(TITLE in line for line in lines), "TITLE is not in the file. Copy a title from the printed notes."
first = next(number for number, line in enumerate(lines) if TITLE in line)
start = next(number for number in range(first, len(lines)) if lines[number].startswith(","))
rows = list(takewhile(str.strip, lines[start:]))
table = pd.read_csv(io.StringIO("\n".join(rows)), index_col=0)
dates = table.index.astype(str).str.strip()
assert (dates.str.len() == 8).all(), "This table is not daily. Pick a table with 8-digit dates."
table.index = pd.to_datetime(dates, format="%Y%m%d")
table.columns = table.columns.str.strip()
table = table.replace([-99.99, -999], float("nan"))

# Step 3. Long format, one row per trading day and series, saved as one CSV file named after FILE and TITLE
panel = table.rename_axis("date").reset_index().melt(id_vars="date", var_name="series", value_name="value")
name = FILE.removesuffix("_CSV.zip") + "_" + (re.sub(r"\W+", "_", TITLE).strip("_") or "first_table")
FOLDER.mkdir(parents=True, exist_ok=True)
panel.to_csv(FOLDER / f"{name}.csv", index=False)
print(len(panel), "rows saved in", FOLDER / f"{name}.csv")

Full post: Fear and greed index backtest since 1927: buying in fear trailed staying invested