search
HomeBackend DevelopmentPython TutorialCalculation of simple statistics in Python

Calculation of simple statistics in Python

Jan 14, 2019 am 10:21 AM
pythondata analysis

The content of this article is about the calculation of simple statistics in Python. It has certain reference value. Friends in need can refer to it. I hope it will be helpful to you.

1. These operations must ensure that the Anaconda integrated library has been installed on the computer. If an error occurs after installation, you can uninstall python in the original computer and reinstall Anaconda. It is recommended to install it during installation. Directly check Add environment variables, otherwise you will have to add environment variables yourself in the future. In the compiler in Pycharm, select python in the Anaconda installation folder. Create a new data folder in Pycharm to store data files.

Calculation of simple statistics in Python

2. Open the Python Console.

3. First use python to read the data. You need to first enter import pandas as pd to introduce the pandas package, then enter df=pd.read_csv("./data/CityData.csv") to read the data, and finally Enter df to display data.

Calculation of simple statistics in Python

4. Enter type(df) and type(df["cid"]) respectively to find that the two data types are different.

Calculation of simple statistics in Python

Calculation of simple statistics in Python

##5. Calculate the average : df.mean() or df["xid"].mean()

Calculation of simple statistics in Python

6. Calculate the median: Enter df.median( ) or df["yid"].median


Calculation of simple statistics in Python

7. Find the quartiles: enter df .quantile(q=0.25)

Calculation of simple statistics in Python

8. Find the mode: enter df.mode() or df["xid"].mode( )

9. Find the standard deviation: enter df.std() or df["yid"].std()

Calculation of simple statistics in Python

10. Calculate variance: df.var() or df["xid"].var()

Calculation of simple statistics in Python

11. Sum: df. sum() or df["xid"].sum()

Calculation of simple statistics in Python

12. Calculate the skew coefficient: df.skew() or df[ "yid"].skew()

Calculation of simple statistics in Python

13. Calculate kurtosis coefficient: df.kurt() or df["yid"].kurt ()

Calculation of simple statistics in Python

14. Generate a normal distribution function. Pandas cannot generate it directly. You need to introduce scipyimport scipy.stats as ss first, and then enter ss. norm, what is generated at this time is a normal distribution object. We enter ss.norm.stats(moments="mvsk") to check. mvsk represents the mean, variance, skewness coefficient, and kurtosis coefficient respectively.

Calculation of simple statistics in Python

At this time we can see that four values ​​are generated, corresponding to the mvsk of the normal distribution, which are 0, 1, 0, and 0 respectively.

15.ss.norm.pdf(0.0) represents the value of the ordinate when the abscissa is 0. ss.norm.ppf(0.9) means that the value obtained when accumulating from negative infinity to the return value is 0.9, where the value after ppf must be between 0-1. ss.norm.cdf(2) represents the return value when integrating from negative infinity to 2, and ss.norm.rvs(size=10) can obtain 10 random numbers that conform to the normal distribution.

Calculation of simple statistics in Python

16.Similarly, we can input ss.chi2 and ss.t to get the chi-square distribution and T distribution respectively.

Calculation of simple statistics in Python

17. In addition, we can also perform sampling, enter df.sample(n=10) to extract 10 samples from the data, enter df. sample(frac=0.1) takes a 10% sample from the data.

Calculation of simple statistics in Python

The above is the detailed content of Calculation of simple statistics in Python. For more information, please follow other related articles on the PHP Chinese website!

Statement
This article is reproduced at:segmentfault. If there is any infringement, please contact admin@php.cn delete
How do you slice a Python list?How do you slice a Python list?May 02, 2025 am 12:14 AM

SlicingaPythonlistisdoneusingthesyntaxlist[start:stop:step].Here'showitworks:1)Startistheindexofthefirstelementtoinclude.2)Stopistheindexofthefirstelementtoexclude.3)Stepistheincrementbetweenelements.It'susefulforextractingportionsoflistsandcanuseneg

What are some common operations that can be performed on NumPy arrays?What are some common operations that can be performed on NumPy arrays?May 02, 2025 am 12:09 AM

NumPyallowsforvariousoperationsonarrays:1)Basicarithmeticlikeaddition,subtraction,multiplication,anddivision;2)Advancedoperationssuchasmatrixmultiplication;3)Element-wiseoperationswithoutexplicitloops;4)Arrayindexingandslicingfordatamanipulation;5)Ag

How are arrays used in data analysis with Python?How are arrays used in data analysis with Python?May 02, 2025 am 12:09 AM

ArraysinPython,particularlythroughNumPyandPandas,areessentialfordataanalysis,offeringspeedandefficiency.1)NumPyarraysenableefficienthandlingoflargedatasetsandcomplexoperationslikemovingaverages.2)PandasextendsNumPy'scapabilitieswithDataFramesforstruc

How does the memory footprint of a list compare to the memory footprint of an array in Python?How does the memory footprint of a list compare to the memory footprint of an array in Python?May 02, 2025 am 12:08 AM

ListsandNumPyarraysinPythonhavedifferentmemoryfootprints:listsaremoreflexiblebutlessmemory-efficient,whileNumPyarraysareoptimizedfornumericaldata.1)Listsstorereferencestoobjects,withoverheadaround64byteson64-bitsystems.2)NumPyarraysstoredatacontiguou

How do you handle environment-specific configurations when deploying executable Python scripts?How do you handle environment-specific configurations when deploying executable Python scripts?May 02, 2025 am 12:07 AM

ToensurePythonscriptsbehavecorrectlyacrossdevelopment,staging,andproduction,usethesestrategies:1)Environmentvariablesforsimplesettings,2)Configurationfilesforcomplexsetups,and3)Dynamicloadingforadaptability.Eachmethodoffersuniquebenefitsandrequiresca

How do you slice a Python array?How do you slice a Python array?May 01, 2025 am 12:18 AM

The basic syntax for Python list slicing is list[start:stop:step]. 1.start is the first element index included, 2.stop is the first element index excluded, and 3.step determines the step size between elements. Slices are not only used to extract data, but also to modify and invert lists.

Under what circumstances might lists perform better than arrays?Under what circumstances might lists perform better than arrays?May 01, 2025 am 12:06 AM

Listsoutperformarraysin:1)dynamicsizingandfrequentinsertions/deletions,2)storingheterogeneousdata,and3)memoryefficiencyforsparsedata,butmayhaveslightperformancecostsincertainoperations.

How can you convert a Python array to a Python list?How can you convert a Python array to a Python list?May 01, 2025 am 12:05 AM

ToconvertaPythonarraytoalist,usethelist()constructororageneratorexpression.1)Importthearraymoduleandcreateanarray.2)Uselist(arr)or[xforxinarr]toconvertittoalist,consideringperformanceandmemoryefficiencyforlargedatasets.

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment