Excel: Overview
Microsoft Excel provides built-in functions for calculating both sample and population standard deviation. These functions are available in all modern versions of Excel.
Excel Functions
| Function | Type | Description |
|---|---|---|
| `STDEV.S()` | Sample | Sample standard deviation (divides by n-1) |
| `STDEV.P()` | Population | Population standard deviation (divides by N) |
| `STDEV()` | Sample | Legacy function, same as STDEV.S |
| `STDEVP()` | Population | Legacy function, same as STDEV.P |
Excel Examples
Excel Formulas
// Data in cells A1:A10
=STDEV.S(A1:A10) // Sample SD
=STDEV.P(A1:A10) // Population SD
// For specific values
=STDEV.S(4, 8, 6, 5, 3) // Returns 1.924
// Ignoring text and logical values
=STDEV.S(A1:A10) // Ignores text
=STDEVA(A1:A10) // Includes text as 0Pro Tip
Use STDEV.S for most real-world analyses. Only use STDEV.P when you're certain you have the complete population.
Python: Overview
Python offers multiple ways to calculate standard deviation. The most common libraries are NumPy, Pandas, and the built-in statistics module.
Using NumPy
Python (NumPy)
import numpy as np
data = [4, 8, 6, 5, 3]
# Population standard deviation (default)
pop_sd = np.std(data)
print(f"Population SD: {pop_sd}") # 1.720
# Sample standard deviation
sample_sd = np.std(data, ddof=1)
print(f"Sample SD: {sample_sd}") # 1.924What is ddof?
ddof stands for "Delta Degrees of Freedom". Setting ddof=1 tells NumPy to divide by (n-1) for sample SD. The default ddof=0 gives population SD.
Using Pandas
Python (Pandas)
import pandas as pd
# Create a DataFrame
df = pd.DataFrame({'scores': [85, 90, 78, 92, 88]})
# Sample SD (default in pandas)
sample_sd = df['scores'].std()
print(f"Sample SD: {sample_sd}")
# Population SD
pop_sd = df['scores'].std(ddof=0)
print(f"Population SD: {pop_sd}")
# Multiple columns at once
df.std() # Returns SD for all numeric columnsQuick Comparison
| Tool | Sample SD | Population SD |
|---|---|---|
| Excel | `STDEV.S()` | `STDEV.P()` |
| NumPy | `np.std(data, ddof=1)` | `np.std(data)` |
| Pandas | `df.std()` | `df.std(ddof=0)` |
| Python statistics | `stdev()` | `pstdev()` |