Σ
SDCalc
ระดับกลางบทเรียน·15 min

คำนวณส่วนเบี่ยงเบนมาตรฐานใน Excel และ Python

บทเรียนทีละขั้นตอนสำหรับการคำนวณส่วนเบี่ยงเบนมาตรฐานใน Excel (STDEV.S, STDEV.P) และ Python (numpy, pandas, statistics) พร้อมตัวอย่างโค้ด

Excel: ภาพรวม

Microsoft Excel มีฟังก์ชันในตัวสำหรับคำนวณส่วนเบี่ยงเบนมาตรฐานทั้งของตัวอย่างและประชากร ฟังก์ชันเหล่านี้มีอยู่ใน Excel ทุกเวอร์ชันสมัยใหม่

ฟังก์ชัน Excel

ฟังก์ชันประเภทคำอธิบาย
`STDEV.S()`ตัวอย่างส่วนเบี่ยงเบนมาตรฐานของตัวอย่าง (หารด้วย n-1)
`STDEV.P()`ประชากรส่วนเบี่ยงเบนมาตรฐานของประชากร (หารด้วย N)
`STDEV()`ตัวอย่างฟังก์ชันรุ่นเก่า เหมือนกับ STDEV.S
`STDEVP()`ประชากรฟังก์ชันรุ่นเก่า เหมือนกับ STDEV.P

ตัวอย่าง 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

เคล็ดลับมือโปร

ใช้ STDEV.S สำหรับการวิเคราะห์ในชีวิตจริงส่วนใหญ่ ใช้ STDEV.P เฉพาะเมื่อคุณแน่ใจว่ามีประชากรครบถ้วนเท่านั้น

Python: ภาพรวม

Python มีหลายวิธีในการคำนวณส่วนเบี่ยงเบนมาตรฐาน ไลบรารีที่ใช้กันมากที่สุดคือ NumPy, Pandas และโมดูล statistics ในตัว

การใช้ 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 คืออะไร?

ddof ย่อมาจาก “Delta Degrees of Freedom” การตั้งค่า ddof=1 บอก NumPy ให้หารด้วย (n-1) สำหรับ SD ตัวอย่าง ค่า ddof=0 ที่เป็นค่าเริ่มต้นจะให้ SD ประชากร

การใช้ 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

การเปรียบเทียบอย่างรวดเร็ว

เครื่องมือSD ตัวอย่าง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()`