# The relationship between Python and data analysis

Commonly used data analysis tools include Python, R language, MATLAB, etc., but in the field of big data analysis, Python is the most popular mainstream programming language. The main reasons are as follows.

1) Python is an interpreted programming language. In the scenario of data analysis, the advantage of an interpreted language is that it does not need to compile and link the code. It only needs to write the program and run it directly, so as to avoid solving the compilation link. problems that arise in the process. At the same time, the Python language syntax and structure are relatively simple, which is convenient for novices who focus on data analysis to quickly grasp.

2) The Python language has a large number of open source libraries and analysis frameworks related to data analysis, which can be used directly, which is very convenient. In addition, Python not only provides a platform for data processing, but it can also interface with many languages (C and Fortran).

3) Python is not only used for data analysis, it has many other uses. For example, Python is a general-purpose programming language, it can also be used as a script, and it can also operate a database; and due to the advent of frameworks such as Django, Python can also be used to develop Web applications in recent years, which makes the data developed by Python. Analysis projects are fully compatible with Web servers, allowing them to be integrated into Web applications.

It can be seen that since Python has many advantages over other data analysis languages, it is the best choice for data analysis.

## Commonly used class library for Python data analysis

A class library is a collection of classes used to implement various functions. Libraries commonly used in Python data analysis include NumPy, pandas, Matplotlib, and SciPy. These libraries play an important role in data analysis. The use of these libraries will be introduced in detail later. This section only provides a brief introduction to these libraries.

#### PythonNumPy

NumPy (Numerical Python) is the basic package for scientific computing in Python, which provides the following functions.

- Fast and efficient multidimensional array object ndarray.
- Functions for performing element-wise calculations on arrays and performing mathematical operations directly on arrays.
- Tools for reading and writing array-based datasets on disk.
- Linear algebra operations, Fourier transforms, and random number generation.
- Tools for integrating C, C++, Fortran code into Python.

In addition to providing Python with fast array processing capabilities, NumPy has another major role in data analysis, as a container for passing data between algorithms. For numeric data, NumPy arrays are much more efficient at storing and manipulating data than the built-in Python data structures. Additionally, libraries written in high-level languages such as C and Fortran can directly manipulate data in NumPy arrays without any data copying.

#### Python pandas

pandas is the core library for data analysis in Python. It is a data analysis package with complex data structures and tools built on NumPy. pandas was originally developed as a financial data analysis tool, therefore, it provides good support for time series analysis. pandas incorporates a large number of libraries and standard data models, providing a large number of functions for fast and easy manipulation of data and the tools needed to efficiently manipulate data sets.

Similar to the core of NumPy is ndarray, pandas is developed around the two core data structures of Series and DataFrame, and Series and DataFrame correspond to one-dimensional sequence and two-dimensional table structure respectively. pandas provides sophisticated indexing capabilities to quickly reshape, slice, aggregate, and subset data.

#### Python Matplotlib

Matplotlib is the most popular Python library for graphing data, and it is ideal for creating graphs for publication. Matplotlib provides a complete set of command APIs similar to MATLAB, which is very suitable for interactive plotting, and it can also be easily used as a plotting control and embedded in GUI applications. The pyplot sub-library of Matplotlib provides a drawing API similar to MATLAB, which makes it convenient for users to quickly draw 2D charts, such as histograms, bar charts, and scatter plots.

Matplotlib also provides a module named pylab, which includes many functions commonly used in NumPy and pyplot, which is convenient for users to quickly calculate and draw. The combination of Matplotlib and IPython provides a very good interactive data drawing environment. The drawn chart is also interactive. Users can use the corresponding tools in the drawing window toolbar to zoom in on a certain area of the chart, or to pan and browse a chart. .

#### Python SciPy

SciPy is a set of open-source Python libraries dedicated to scientific computing. It builds on NumPy and provides a toolset for scientific computing in Python. SciPy is often used with core libraries such as NumPy, pandas, Matplotlib and IPython. SciPy mainly includes 8 packages, which correspond to different scientific computing fields. The main packages included in SciPy are shown in Table 1.

Package names | describe |
---|---|

scipy.integrate | Numerical integration routines and differential equation solvers |

scipy.linalg | Extends the linear algebra routines and matrix factorization functions provided by numpy.linalg |

scipy.optimize | Function optimizers (minimizers) and trace-finding algorithms |

scipy.signal | Signal Processing Tools |

scipy.sparse | Sparse matrix and sparse linear system solvers |

scipy.special | A wrapper for SPECFUN, a Fortran library that implements many common mathematical functions |

scipy.stats | Standard continuous and discrete probability distributions (such as density functions, samplers, continuous distribution functions, etc.), various statistical tests, and better descriptive statistics |

scipy.weave | Tools to speed up array computations with inline C++ code |

Note: The organic combination of NumPy and SciPy can completely replace the computing function of MATLAB.

#### Python scikit-learn

scikit-learn is a simple and effective data mining and data analysis tool that can be reused by users in various environments, and scikit-learn is based on NumPy, SciPy and Matplotlib, and some commonly used algorithms are implemented. package.

The basic functions of scikit-learn are mainly divided into six parts: classification, regression, clustering, data dimensionality reduction, model selection and data preprocessing. In the case of a small amount of data, scikit-learn can solve most problems. Users who are not proficient in algorithms do not need to write all the algorithms themselves when performing modeling tasks, but simply call the modules in the scikit-learn library.

#### Python IPython

IPython is part of the standard toolset for scientific computing in Python, which provides a productive development environment for interactive and exploratory computing. It is an enhanced Python shell designed to speed up writing, testing, and debugging Python code, primarily for interactive data processing and data visualization with Matplotlib.

In addition to the standard basic terminal Python shell, the project provides the following features:

- A data analysis software similar to Mathematica with a Notebook editing window that connects to IPython via a web browser.
- A GUI console based on the Qt framework with functions such as plotting, multi-line editing and syntax highlighting.
- A basic framework for interactive parallel and distributed computing.