Pandas (software)

Pandas (styled as pandas) is a software library written for the Python programming language for data manipulation and analysis. In particular, it offers data structures and operations for manipulating numerical tables and time series. It is free software released under the three-clause BSD license. The name is derived from the term "panel data", an econometrics term for data sets that include observations over multiple time periods for the same individuals, as well as a play on the phrase "Python data analysis". Wes McKinney started building what would become Pandas at AQR Capital while he was a researcher there from 2007 to 2010.

The development of Pandas introduced into Python many comparable features of working with DataFrames that were established in the R programming language. The library is built upon another library, NumPy.

History
Developer Wes McKinney started working on Pandas in 2008 while at AQR Capital Management out of the need for a high performance, flexible tool to perform quantitative analysis on financial data. Before leaving AQR he was able to convince management to allow him to open source the library.

Another AQR employee, Chang She, joined the effort in 2012 as the second major contributor to the library.

In 2015, Pandas signed on as a fiscally sponsored project of NumFOCUS, a 501(c)(3) nonprofit charity in the United States.

Data Model
Pandas is built around data structures called Series and DataFrames. Data for these collections can be imported from various file formats such as comma-separated values, JSON, Parquet, SQL database tables or queries, and Microsoft Excel.

A Series is a 1-dimensional data structure built on top of NumPy's array. Unlike in NumPy, each data point has an associated label. The collection of these labels is called an index. Series can be used arithmetically, as in the statement : this will align data points with corresponding index values in   and , then add them together to produce new values in. A DataFrame is a 2-dimensional data structure of rows and columns, similar to a spreadsheet, and analogous to a Python dictionary mapping column names (keys) to Series (values), with each Series sharing an index. DataFrames can be concatenated together or "merged" on columns or indices in a manner similar to joins in SQL. Pandas implements a subset of relational algebra, and supports one-to-one, many-to-one, and many-to-many joins. Pandas also supports the less common Panel and Panel4D, which are 3-dimensional and 4-dimension data structures respectively.

Users can transform or summarize data by applying arbitrary functions. Since Pandas is built on top of NumPy, all NumPy functions work on Series and DataFrames as well. Pandas also includes built-in operations for arithmetic, string manipulation, and summary statistics such as mean, median, and standard deviation. These built-in functions are designed to handle missing data, usually represented by the floating-point value NaN.

Subsets of data can be selected by column name, index, or Boolean expressions. For example,  will return all rows in the DataFrame   for which the value of the column   exceeds 5. Data can be grouped together by a column value, as in, or by a function which is applied to the index. For example,  groups data by whether the index is even.

Pandas includes support for time series, such as the ability to interpolate values and filter using a range of timestamps (e.g.   will return all dates between January 1st and February 2nd). Pandas represents missing time series data using a special NaT (Not a Timestamp) object, instead of the NaN value it uses elsewhere.

Indices
By default, a Pandas index is a series of integers ascending from 0, similar to the indices of Python arrays. However, indices can use any NumPy data type, including floating point, timestamps, or strings.

Pandas' syntax for mapping index values to relevant data is the same syntax Python uses to map dictionary keys to values. For example, if  is a Series,   will return the data point at index. Unlike dictionary keys, index values are not guaranteed to be unique. If a Series uses the index value  for multiple data points, then   will instead return a new Series containing all matching values. A DataFrame's column names are stored and implemented identically to an index. As such, a DataFrame can be thought of as having two indices: one column-based and one row-based. Because column names are stored as an index, there are also not required to be unique.

If  is a Series, then   returns all values with the index value of. However, if  is a DataFrame, then   returns all values in the column(s) named. To avoid this ambiguity, Pandas supports the syntax  as an alternative way to filter using the index. Pandas also supports the syntax, which always takes an integer n and returns the nth value, counting from 0. This allows a user to act as though the index is an array-like sequence of integers, regardless of how it's actually defined.

Pandas supports hierarchical indices with multiple values per data point. An index with this structure, called a "MultiIndex", allows a single DataFrame to represent multiple dimensions, similar to a pivot table in Microsoft Excel. Each level of a MultiIndex can be given a unique name. In practice, data with more than 2 dimensions is often represented using DataFrames with hierarchical indices, instead of the higher-dimension Panel and Panel4D data structures

Criticisms
Pandas has been criticized for its inefficiency. Pandas can require 5 to 10 times as much memory as the size of the underlying data, and the entire dataset must be loaded in RAM. The library does not optimize query plans or support parallel computing across multiple cores. Wes McKinney, the creator of Pandas, has recommended Apache Arrow as an alternative to address these performance concerns and other limitations.