Σ
SDCalc
Trung cấpHướng dẫn·15 min

Tính Độ lệch chuẩn trong Excel và Python

Hướng dẫn từng bước tính độ lệch chuẩn trong Excel (STDEV.S, STDEV.P) và Python (numpy, pandas, statistics). Kèm ví dụ mã nguồn.

Excel: Tổng quan

Microsoft Excel cung cấp các hàm tích hợp để tính cả độ lệch chuẩn mẫu và tổng thể. Các hàm này có sẵn trong tất cả phiên bản Excel hiện đại.

Các hàm Excel

HàmLoạiMô tả
`STDEV.S()`MẫuĐộ lệch chuẩn mẫu (chia cho n-1)
`STDEV.P()`Tổng thểĐộ lệch chuẩn tổng thể (chia cho N)
`STDEV()`MẫuHàm cũ, tương tự STDEV.S
`STDEVP()`Tổng thểHàm cũ, tương tự STDEV.P

Ví dụ Excel

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 0

Mẹo hữu ích

Sử dụng STDEV.S cho hầu hết các phân tích thực tế. Chỉ dùng STDEV.P khi bạn chắc chắn có toàn bộ tổng thể.

Python: Tổng quan

Python cung cấp nhiều cách để tính độ lệch chuẩn. Các thư viện phổ biến nhất là NumPy, Pandas và module statistics tích hợp sẵn.

Sử dụng 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.924

ddof là gì?

ddof là viết tắt của “Delta Degrees of Freedom” (Delta bậc tự do). Đặt ddof=1 yêu cầu NumPy chia cho (n-1) để tính SD mẫu. Giá trị mặc định ddof=0 cho SD tổng thể.

Sử dụng 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 columns

So sánh nhanh

Công cụSD mẫuSD tổng thể
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()`

Further Reading

How to Read This Article

A statistics tutorial is a practical interpretation guide, not just a formula dump. It refers to the assumptions, notation, and reporting language that analysts need when they explain a result to a teacher, manager, client, or reviewer. The article body covers the specific topic, while the sections below create a common interpretation frame that readers can reuse across related metrics.

Reading goalWhat to focus onCommon mistake
DefinitionWhat the metric is and what quantity it summarizesTreating the formula as self-explanatory
Formula choiceSample versus population assumptions and notationUsing n when n-1 is required or vice versa
InterpretationWhether the result indicates concentration, spread, or riskCalling a large value good or bad without context

Frequently Asked Questions

How should I interpret a high standard deviation?

A high standard deviation means the observations are spread farther from the mean on average. Whether that spread is acceptable depends on the context: wide dispersion might signal risk in finance, instability in manufacturing, or genuine natural variation in scientific data.

Why do some articles mention n while others mention n-1?

The denominator reflects the difference between population and sample formulas. Population variance and population standard deviation use N because the full dataset is known. Sample variance and sample standard deviation often use n-1 because Bessel’s correction reduces bias when estimating population spread from a sample.

What is a statistical interpretation guide?

A statistical interpretation guide is a page that moves beyond arithmetic and explains meaning. It tells you what a metric is, when the formula applies, and how to describe the result in plain English without overstating certainty.

Can I cite this article in a report?

You should cite the underlying authoritative reference for formal work whenever possible. This page is best used as an explanatory bridge that helps you understand the concept before quoting the original standard or handbook.

Why include direct citations on every article page?

Direct citations give readers a route to verify the definition, notation, and assumptions. That improves trust and reduces the chance that a simplified explanation is mistaken for the entire technical standard.

Authoritative References

These sources define the concepts referenced most often across our articles. Bessel's correction is a sample adjustment, variance is a squared measure of spread, and standard deviation is the square root of variance expressed in the same units as the data.