Pandas

Short description: Python library for data analysis

Pandas

Original author(s)| Wes McKinney
Developer(s)| Community
Initial release| 11 January 2008; 18 years ago (2008-01-11) [citation needed]
Preview release|

2.0rc1 / 15 March 2023

Written in| Python, Cython, C
Operating system| Cross-platform
Type| Technical computing
License| New BSD License
Website| pandas.pydata.org

Pandas (stylized 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.[1] 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,[2] as well as a play on the phrase "Python data analysis".[3]: 5 Wes McKinney started building what would become Pandas at AQR Capital while he was a researcher there from 2007 to 2010.[4]

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.

## Contents

* 1 History
* 2 Data Model
* 2.1 Indices
* 3 Criticisms
* 4 See also
* 5 References
* 6 Further reading

## 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.[5]

## 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.[6]

A Series is a 1-dimensional data structure built on top of NumPy's array.[7]: 97 Unlike in NumPy, each data point has an associated label. The collection of these labels is called an index.[3]: 112 Series can be used arithmetically, as in the statement `series_3 = series_1 + series_2`: this will align data points with corresponding index values in `series_1` and `series_2`, then add them together to produce new values in `series_3`.[3]: 114 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.[3]: 115 DataFrames can be concatenated together or "merged" on columns or indices in a manner similar to joins in SQL.[3]: 177–182 Pandas implements a subset of relational algebra, and supports one-to-one, many-to-one, and many-to-many joins.[7]: 147–148 Pandas also supports the less common Panel and Panel4D, which are 3-dimensional and 4-dimension data structures respectively.[7]: 141

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

Subsets of data can be selected by column name, index, or Boolean expressions. For example, `df[df['col1'] > 5]` will return all rows in the DataFrame `df` for which the value of the column `col1` exceeds 5.[3]: 126–128 Data can be grouped together by a column value, as in `df['col1'].groupby(df['col2'])`, or by a function which is applied to the index. For example, `df.groupby(lambda i: i % 2)` groups data by whether the index is even.[3]: 253–259

Pandas includes support for time series, such as the ability to interpolate values [3]: 316–317 and filter using a range of timestamps (e.g. `data['1/1/2023':'2/2/2023']` will return all dates between January 1st and February 2nd).[3]: 295 Pandas represents missing time series data using a special NaT (Not a Timestamp) object, instead of the NaN value it uses elsewhere.[3]: 292

### 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.[3]: 112

Pandas' syntax for mapping index values to relevant data is the same syntax Python uses to map dictionary keys to values. For example, if `s` is a Series, `s['a']` will return the data point at index `a`. Unlike dictionary keys, index values are not guaranteed to be unique. If a Series uses the index value `a` for multiple data points, then `s['a']` will instead return a new Series containing all matching values.[3]: 136 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.[7]: 103–105

If `data` is a Series, then `data['a']` returns all values with the index value of `a`. However, if `data` is a DataFrame, then `data['a']` returns all values in the column(s) named `a`. To avoid this ambiguity, Pandas supports the syntax `data.loc['a']` as an alternative way to filter using the index. Pandas also supports the syntax `data.iloc[n]`, 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.[7]: 110–113

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.[3]: 147–148 Each level of a MultiIndex can be given a unique name.[7]: 133 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[7]: 128

## 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.[8]

## See also

* matplotlib
* NumPy
* Dask
* SciPy
* R (programming language)
* scikit-learn
* statsmodels
* List of numerical analysis software

## References

1. ↑ "License – Package overview – pandas 1.0.0 documentation". 28 January 2020. https://pandas.pydata.org/pandas-docs/stable/overview.html#license.
2. ↑ Wes McKinney (2011). "pandas: a Foundational Python Library for Data Analysis and Statistics". https://www.dlr.de/sc/Portaldata/15/Resources/dokumente/pyhpc2011/submissions/pyhpc2011_submission_9.pdf.
3. ↑ 3.00 3.01 3.02 3.03 3.04 3.05 3.06 3.07 3.08 3.09 3.10 3.11 3.12 3.13 3.14 3.15 McKinney, Wes (2014). Python for Data Analysis (First ed.). O'Reilly. ISBN 978-1-449-31979-3.
4. ↑ Kopf, Dan. "Meet the man behind the most important tool in data science" (in en). https://qz.com/1126615/the-story-of-the-most-important-tool-in-data-science/.
5. ↑ "NumFOCUS – pandas: a fiscally sponsored project". https://www.numfocus.org/project/pandas/.
6. ↑ "IO tools (Text, CSV, HDF5, …) — pandas 1.4.1 documentation". https://pandas.pydata.org/pandas-docs/stable/user_guide/io.html.
7. ↑ 7.0 7.1 7.2 7.3 7.4 7.5 7.6 7.7 VanderPlas, Jake (2016). Python Data Science Handbook: Essential Tools for Working with Data (First ed.). O'Reilly. ISBN 978-1-491-91205-8.
8. ↑ McKinney, Wes (21 September 2017). "Apache Arrow and the "10 Things I Hate About pandas"" (in en). https://wesmckinney.com/blog/apache-arrow-pandas-internals/.

## Further reading

* McKinney, Wes (2017). Python for Data Analysis : Data Wrangling with Pandas, NumPy, and IPython (2nd ed.). Sebastopol: O'Reilly. ISBN 978-1-4919-5766-0.
* Molin, Stefanie (2019). Hands-On Data Analysis with Pandas: Efficiently perform data collection, wrangling, analysis, and visualization using Python. Packt. ISBN 978-1-7896-1532-6.
* Chen, Daniel Y. (2018). Pandas for Everyone : Python Data Analysis. Boston: Addison-Wesley. ISBN 978-0-13-454693-3.
* VanderPlas, Jake (2016). "Data Manipulations with Pandas". Python Data Science Handbook: Essential Tools for Working with Data. O'Reilly. pp. 97–216. ISBN 978-1-4919-1205-8.
* Pathak, Chankey (2018). Pandas Cookbook. pp. 1–8.

* v
* t
* e

Scientific software in Python

* NumPy
* SciPy
* matplotlib
* pandas
* scikit-learn
* scikit-image
* statsmodels
* MayaVi
* more

0.00

(0 votes)

|

Retrieved from "https://handwiki.org/wiki/index.php?title=Software:Pandas&oldid=718825"
*[v]: View this template
*[t]: Discuss this template
*[e]: Edit this template