When first starting to learn Python, I found the array of package names and libraries a bit bewildering and confusing. In this post I will enumerate many of the most common and useful parts of the Python computing “ecosystem” and attempt to describe them very briefly.
My aim is to provide some clarity on the situation for new users, as I would have liked to have seen the “30,000 ft view” when I started learning not long ago. So without further ado, part 1 of the python ecosystem overview:
Python -high-level, interpreted language
Python is an interpreted programming language (itself written in C) that allows you to write very clean and simple code in a fast and human-readable form as compared to lower-level compiled languages (C++, Fortran).
The language is simple, self-consistent and beautiful. It is relatively easy to learn and is gaining in popularity every year. The simplicity and ease of use does come with a price as code written in pure Python is generally slower to execute than compiled C/C++ code.
iPython -get code written faster
iPython is an enhanced, interactive Python shell designed to make code development faster. According to Wes McKinney in his excellent book, “Python for Data Analysis,” iPython is designed to encourage “an execute-explore workflow instead of the typical edit-compile-run workflow of many other programming languages.”
iPython contains the Python interpreter and is ready to execute commands as you enter them. It is where you run code snippets, examine the outputs, and make iterative improvements. In that sense, it is like kind of like the UNIX command line. You don’t write full programs here, you do that in a text editor or IDE (integrated development environment).
It also contains useful features called “magic commands.” These are commands that are unique to the iPython command line, and are not valid Python code (i.e., you cannot use these commands in stand-alone programs). Magic commands provide productivity speedups in many useful ways, such as recalling command history, running parts of scripts, timing code, and debugging code interactively.
If you have iPython installed you can invoke it from a regular python shell; however I find it easiest to use it within an IDE that supports iPython.
iPython Notebook -share code and ideas over the web
The iPython notebook is an interactive python format that runs in a web browser or in an IDE. The Notebook is a flexible and powerful document format that allows python code, text markdown, mathematics equations, and figures to be displayed together in a coherent, inline way. An iPython notebook could be used to provide all of the steps in a data analysis project, for example, or to teach a programming concept. It is very useful for sharing code and visualizing results in an interactive, portable document.
NumPy -implement very fast vectorized computation
NumPy (numerical python) is a powerful and fast library for doing numerical computation in Python. It is based on a data structure called an ndarray. This lower level structure is faster for computation than regular higher-level python structures like lists and dictionaries, but it is less flexible and behaves in somewhat unintuitive ways. Functions can be applied across a numpy array all at once and “in place”; this is known as vectorization. NumPy contains a number of vectorized built-in functions known as “ufuncs” for doing transformations on ndarrrays.
pandas -powerful library for data analysis
pandas is a data analysis package for python; conceived and built initially by Wes McKinney. It was developed to allow python users to access some of the powerful features of the R statistics language while staying in the python ecosystem. Prior to the development of pandas, data analysis had to be carried out using the NumPy ndarray structures which are rather difficult for handling messy real world data.
Pandas achieves very fast speeds and efficiency because it is built on top of NumPy and therefore takes advantage of the built-in speed advantage of the low-level ndarray data structures. However, pandas allows users to create higher-level structures called Series (1D), Dataframes (2D) and Panels (3D), that are more flexible and useful for regular data analysis than raw numpy arrays owing to their ability to contain mixed data types, headers, and indexes.
Pandas also contains many built-in methods for operations on Series, Dataframes, and Panels that allow users to quickly and easily do data aggregation, reductions, and “split-apply-combine” strategies.
SciPy -collection of libraries for a variety of computing applications
SciPy is a collection of scientific algorithms for doing scientific computing. It is an open-source project under active development. Some of the packages available include scipy.linalg for doing linear algebra, scipy.stats for statistics, scipy.cluster for clustering (K-means and others), scipy.fftpack for doing fourier transform analysis, scipy.optimize for doing curve fitting and minimization, and scipy.signal for doing signal processing. There are many more packages in SciPy; what you end up using will depend on your application and area of interest.
In part 2, I will describe even more libraries and packages that you will encounter as you learn scientific computing with Python.
One Reply to “The Python ecosystem for beginners”