Python statistics मॉड्यूल
In this page:
import statistics
statistics.mean(data)
statistics.median(data)
statistics.stdev(data)
Central Tendency
Built-in statistics मॉड्यूल सामान्य calculations के लिए simple, dependency-free functions देता है: statistics.mean() arithmetic average निकालता है और statistics.median() sorted dataset की middle value ढूँढता है, जो mean की तुलना में outliers के प्रति ज़्यादा robust है।
उदाहरण: Central Tendency
import statistics
data = [1, 2, 3, 4, 100]
print(statistics.mean(data)) # arithmetic average, pulled up by the outlier
print(statistics.median(data)) # middle value, unaffected by the outlier
Mode और Frequency
statistics.mode() किसी dataset में सबसे ज़्यादा बार आने वाली एक value लौटाता है, जबकि statistics.multimode() एक से ज़्यादा होने पर सबसे frequent के लिए tied सारी values लौटाता है।
Mode central tendency का एकमात्र माप है जो non-numeric, categorical data के लिए भी अर्थपूर्ण है।
उदाहरण: Mode and Frequency
import statistics
data = [1, 2, 2, 3]
print(statistics.mode(data)) # the single most frequent value
print(statistics.multimode([1, 1, 2, 2, 3])) # all values tied for most frequent
Dispersion के माप
statistics.variance() और statistics.stdev() यह बताते हैं कि dataset की values mean के चारों ओर कितनी फैली हुई हैं -- छोटा standard deviation मतलब values एक साथ tightly cluster हैं, बड़ा मतलब वो widely scattered हैं।
दोनों population और sample variants में आते हैं (pvariance/pstdev बनाम variance/stdev), और गलत वाला चुनना छोटे datasets के लिए results को skew कर देता है।
उदाहरण: Dispersion Measures
import statistics
data = [2, 4, 4, 4, 5, 5, 7, 9]
print(statistics.variance(data)) # sample variance
print(statistics.stdev(data)) # sample standard deviation
Data Distribution Ranges
statistics.median_low() और statistics.median_high() उस अस्पष्टता को सुलझाते हैं जो तब आती है जब dataset में values की संख्या even हो और कोई single middle element न हो -- ये दोनों central values को average करने की बजाय क्रमशः निचली और ऊपरी value लौटाते हैं।
उदाहरण: Data Distribution Ranges
import statistics
data = [1, 2, 3, 4]
print(statistics.median_low(data)) # lower of the two middle values
print(statistics.median_high(data)) # upper of the two middle values
Harmonic और Geometric Means
statistics.geometric_mean() और statistics.harmonic_mean() विशिष्ट स्थितियों के लिए बने specialized averages हैं: geometric mean growth rates या ratios का average निकालने के लिए उपयुक्त है, और harmonic mean speed जैसी rates का average निकालने के लिए उपयुक्त है, जहाँ arithmetic mean भ्रामक जवाब देता।
उदाहरण: Harmonic and Geometric Means
import statistics
data = [2, 8]
print(statistics.geometric_mean(data)) # suited to averaging rates of growth
print(statistics.harmonic_mean(data)) # suited to averaging rates like speed
Chapter Quiz — Complete all 14 topics to unlock
0/14 topics done
Complete these topics first:
- Python NumPy Introduction
- Python NumPy Arrays
- Python Pandas Introduction
- Python Pandas DataFrame
- Python Matplotlib Basics
- Python Data Visualization
- Python Statistics Module
- Python CSV & Data Analysis
- Python requests Module
- Python JSON & APIs
- Python Web Scraping Basics
- Python Flask Introduction
- Python Django Introduction
- Python MongoDB