The Interpreter and Its Environment 2. Source Code Encoding 3. An Informal Introduction to Python 3. Using Python as a Calculator 3. Numbers 3. Strings 3. Lists 3. First Steps Towards Programming 4. More Control Flow Tools 4. The range Function 4. Defining Functions 4. More on Defining Functions 4. Default Argument Values 4. Keyword Arguments 4. Special parameters 4.
Positional-or-Keyword Arguments 4. Positional-Only Parameters 4. Keyword-Only Arguments 4. Function Examples 4. Recap 4. Arbitrary Argument Lists 4. Unpacking Argument Lists 4. Lambda Expressions 4. Documentation Strings 4.
Function Annotations 4. Intermezzo: Coding Style 5. Data Structures 5. More on Lists 5. Using Lists as Stacks 5. Using Lists as Queues 5. List Comprehensions 5. Nested List Comprehensions 5. The del statement 5. Tuples and Sequences 5. Sets 5. Dictionaries 5. Looping Techniques 5. More on Conditions 5. Comparing Sequences and Other Types 6. Modules 6. More on Modules 6. Executing modules as scripts 6. The Module Search Path 6. Standard Modules 6.
The dir Function 6. Packages 6. Intra-package References 6. Packages in Multiple Directories 7. Input and Output 7. Fancier Output Formatting 7. Formatted String Literals 7. The String format Method 7. Manual String Formatting 7.
Old string formatting 7. Reading and Writing Files 7. Methods of File Objects 7. Saving structured data with json 8. Errors and Exceptions 8. Syntax Errors 8. Exceptions 8. Handling Exceptions 8. Raising Exceptions 8. Exception Chaining 8. User-defined Exceptions 8. Defining Clean-up Actions 8. Predefined Clean-up Actions 9. Classes 9. A Word About Names and Objects 9. Python Scopes and Namespaces 9. Scopes and Namespaces Example 9.
A First Look at Classes 9. Class Definition Syntax 9. Class Objects 9. If data is empty, StatisticsError is raised. The median is a robust measure of central location and is less affected by the presence of outliers. When the number of data points is odd, the middle data point is returned:. When the number of data points is even, the median is interpolated by taking the average of the two middle values:.
Return the low median of numeric data. The low median is always a member of the data set. When the number of data points is odd, the middle value is returned. When it is even, the smaller of the two middle values is returned. Use the low median when your data are discrete and you prefer the median to be an actual data point rather than interpolated. Return the high median of data. The high median is always a member of the data set. When it is even, the larger of the two middle values is returned.
Use the high median when your data are discrete and you prefer the median to be an actual data point rather than interpolated. Return the median of grouped continuous data, calculated as the 50th percentile, using interpolation. In the following example, the data are rounded, so that each value represents the midpoint of data classes, e.
With the data given, the middle value falls somewhere in the class 3. Optional argument interval represents the class interval, and defaults to 1. Changing the class interval naturally will change the interpolation:. This behaviour is likely to change in the future. Return the single most common data point from discrete or nominal data. The mode when it exists is the most typical value and serves as a measure of central location. If there are multiple modes with the same frequency, returns the first one encountered in the data.
If the smallest or largest of those is desired instead, use min multimode data or max multimode data. If the input data is empty, StatisticsError is raised. This is the standard treatment of the mode as commonly taught in schools:. The mode is unique in that it is the only statistic in this package that also applies to nominal non-numeric data:.
Changed in version 3. Formerly, it raised StatisticsError when more than one mode was found. Return a list of the most frequently occurring values in the order they were first encountered in the data. Will return more than one result if there are multiple modes or an empty list if the data is empty:. Return the population standard deviation the square root of the population variance.
See pvariance for arguments and other details. Return the population variance of data , a non-empty sequence or iterable of real-valued numbers.
Variance, or second moment about the mean, is a measure of the variability spread or dispersion of data. A large variance indicates that the data is spread out; a small variance indicates it is clustered closely around the mean. If the optional second argument mu is given, it is typically the mean of the data. It can also be used to compute the second moment around a point that is not the mean. If it is missing or None the default , the arithmetic mean is automatically calculated.
Use this function to calculate the variance from the entire population. To estimate the variance from a sample, the variance function is usually a better choice. Raises StatisticsError if data is empty. If you have already calculated the mean of your data, you can pass it as the optional second argument mu to avoid recalculation:.
Provided the data points are a random sample of the population, the result will be an unbiased estimate of the population variance. Return the sample standard deviation the square root of the sample variance. See variance for arguments and other details. Return the sample variance of data , an iterable of at least two real-valued numbers. If the optional second argument xbar is given, it should be the mean of data. If it is missing or None the default , the mean is automatically calculated. Use this function when your data is a sample from a population.
To calculate the variance from the entire population, see pvariance. Raises StatisticsError if data has fewer than two values. If you have already calculated the mean of your data, you can pass it as the optional second argument xbar to avoid recalculation:. This function does not attempt to verify that you have passed the actual mean as xbar.
Using arbitrary values for xbar can lead to invalid or impossible results. Provided that the data points are representative e. Divide data into n continuous intervals with equal probability. Returns a list of n - 1 cut points separating the intervals. Set n to 4 for quartiles the default. Set n to 10 for deciles. Set n to for percentiles which gives the 99 cuts points that separate data into equal sized groups.
Raises StatisticsError if n is not least 1. The data can be any iterable containing sample data. For meaningful results, the number of data points in data should be larger than n. Raises StatisticsError if there are not at least two data points. The cut points are linearly interpolated from the two nearest data points. For example, if a cut point falls one-third of the distance between two sample values, and , the cut-point will evaluate to The method for computing quantiles can be varied depending on whether the data includes or excludes the lowest and highest possible values from the population.
The minimum value in data is treated as the 0th percentile and the maximum value is treated as the th percentile. Subclass of ValueError for statistics-related exceptions. NormalDist is a tool for creating and manipulating normal distributions of a random variable. It is a class that treats the mean and standard deviation of data measurements as a single entity. Normal distributions arise from the Central Limit Theorem and have a wide range of applications in statistics.
Returns a new NormalDist object where mu represents the arithmetic mean and sigma represents the standard deviation.
0コメント