Σ
SDCalc
ØvetVejledninger·15 min

Beregn standardafvigelse i Excel og Python

Trinvise vejledninger til beregning af standardafvigelse i Excel (STDEV.S, STDEV.P) og Python (numpy, pandas, statistics). Med kodeeksempler.

Excel: Oversigt

Microsoft Excel har indbyggede funktioner til beregning af både stikprøve- og populationsstandardafvigelse. Disse funktioner er tilgængelige i alle moderne versioner af Excel.

Excel-funktioner

FunktionTypeBeskrivelse
`STDEV.S()`StikprøveStikprøvestandardafvigelse (dividerer med n-1)
`STDEV.P()`PopulationPopulationsstandardafvigelse (dividerer med N)
`STDEV()`StikprøveÆldre funktion, samme som STDEV.S
`STDEVP()`PopulationÆldre funktion, samme som STDEV.P

Excel-eksempler

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

Professionelt tip

Brug STDEV.S til de fleste analyser i den virkelige verden. Brug kun STDEV.P, når du er sikker på, at du har den komplette population.

Python: Oversigt

Python tilbyder flere måder at beregne standardafvigelse på. De mest almindelige biblioteker er NumPy, Pandas og det indbyggede statistics-modul.

Med 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

Hvad er ddof?

ddof står for “Delta Degrees of Freedom” (delta-frihedsgrader). At sætte ddof=1 fortæller NumPy at dividere med (n-1) for stikprøve-SA. Standard ddof=0 giver populations-SA.

Med 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

Hurtig sammenligning

VærktøjStikprøve-SAPopulations-SA
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()`