Introduction
Free Cash Flow (FCF) measures the cash an company generates after covering operating expenses and investments. Unlike net income, which can be manipulated through accounting, FCF shows real cash: money available for dividends, buybacks, or growth.
Why it matters in 2026? With persistent inflation and high interest rates, investors prioritize companies with strong FCF for resilience. For example, Apple generated $110 billion in FCF in 2023, funding its innovations. This beginner tutorial guides you step by step: from the basic formula FCF = CFO - Capex to a complete Python script analyzing real data. By the end, you'll calculate and visualize FCF like a pro, ready to evaluate any public company.
Prerequisites
- Python 3.10+ installed
- Basic accounting knowledge (CFO, Capex)
- Code editor (VS Code recommended)
- Libraries: pandas, numpy, matplotlib (installed via tutorial)
Install the dependencies
pip install pandas numpy matplotlib openpyxlThese commands install pandas for handling tabular data, numpy for numerical calculations, matplotlib for charts, and openpyxl for reading Excel files. Run them in your terminal for a ready-to-use environment.
The Free Cash Flow Formula
The standard formula is FCF = Cash from operations (CFO) - Capital expenditures (Capex).
- CFO: Cash generated from core operations (sales minus cash costs).
- Capex: Investments in fixed assets (factories, equipment).
Basic FCF Calculation
cfo = 100_000_000 # Cash from operations in euros
capex = 30_000_000 # Capital expenditures
fcf = cfo - capex
print(f"Free Cash Flow : {fcf:,.0f} €")
print(f"Marge FCF/CFO : {fcf/cfo*100:.1f}%")This script calculates FCF for a simple example and displays the margin. Underscores make large numbers readable. Copy-paste and run: python fcf_simple.py to see 'Free Cash Flow : 70,000,000 €'.
Prepare Real Data
Let's use Apple data (2020-2023, in billions USD, source: 10-K reports). Create a file apple_data.xlsx with these columns: Year, CFO, Capex.
| Year | CFO | Capex |
|---|---|---|
| ------ | -------- | ------- |
| 2020 | 80.97 | 7.31 |
| 2021 | 104.04 | 10.97 |
| 2022 | 122.15 | 10.66 |
| 2023 | 110.54 | 10.96 |
Load and Clean Data
import pandas as pd
import numpy as np
# Load the Excel file (create apple_data.xlsx with the data)
df = pd.read_excel('apple_data.xlsx')
# Clean: convert to float, handle NaN
df['CFO'] = pd.to_numeric(df['CFO'], errors='coerce')
df['Capex'] = pd.to_numeric(df['Capex'], errors='coerce')
df = df.dropna()
print(df)
print("Data ready for FCF calculation.")This code reads the Excel file, converts columns to numbers, and drops empty rows. pd.to_numeric prevents errors from strings. Result: Clean DataFrame with 4 rows for Apple.
Calculate FCF Over Multiple Years
import pandas as pd
# Hardcoded data if no Excel (copied from prerequisites)
data = {
'Annee': [2020, 2021, 2022, 2023],
'CFO': [80.97, 104.04, 122.15, 110.54],
'Capex': [7.31, 10.97, 10.66, 10.96]
}
df = pd.DataFrame(data)
# Calculate FCF
df['FCF'] = df['CFO'] - df['Capex']
# Add FCF/CFO margin
df['Marge_FCF'] = (df['FCF'] / df['CFO']) * 100
print(df.round(2))
print(f"FCF moyen : {df['FCF'].mean():.2f} milliards USD")Standalone script with hardcoded Apple data. Adds FCF and margin columns. Output: Table with 2023 FCF = 99.58B USD, 90% margin. Great if no Excel; extensible to any CSV.
Visualize FCF Trends
import pandas as pd
import matplotlib.pyplot as plt
# Reuse data and calculations from previous script
data = {'Annee': [2020, 2021, 2022, 2023], 'CFO': [80.97, 104.04, 122.15, 110.54], 'Capex': [7.31, 10.97, 10.66, 10.96]}
df = pd.DataFrame(data)
df['FCF'] = df['CFO'] - df['Capex']
# Plot
plt.figure(figsize=(10, 6))
plt.plot(df['Annee'], df['FCF'], marker='o', linewidth=2, label='FCF')
plt.plot(df['Annee'], df['CFO'], marker='s', label='CFO')
plt.plot(df['Annee'], df['Capex'], marker='^', label='Capex')
plt.title('Évolution Free Cash Flow - Apple (2020-2023)')
plt.xlabel('Année')
plt.ylabel('Milliards USD')
plt.legend()
plt.grid(True, alpha=0.3)
plt.show()This script generates a line chart comparing FCF, CFO, and Capex. plt.show() displays the plot; save with plt.savefig('fcf_apple.png'). See growth from 73.66B to 99.58B USD.
Best Practices
- Always normalize units: Convert to billions or thousands to avoid scale errors.
- Verify sources: Use official reports (10-K) over third-party sites for accurate CFO/Capex.
- Adjust for levered/unlevered FCF: Subtract net debt for DCF valuation.
- Compare to industry: FCF margin > 10-15% is solid for tech.
- Automate: Integrate yfinance for live data (
pip install yfinance).
Common Mistakes to Avoid
- Confusing total Capex and maintenance: Use growth Capex + maintenance for precision (beyond this beginner tutorial).
- Ignoring working capital changes: Included in CFO, but verify the accounting.
- Unadjusted data: Forget currencies or inflation; normalize to constant USD.
- No sanity check: Persistent negative FCF means cash burn—steer clear!
Next Steps
Master DCF valuation with projected FCF. Check out yfinance for automated data.
Explore our Learni courses on data-driven finance: Python for financial analysts, advanced DCF modeling. Join 5000+ trained pros.