What pandas is and how it works
pandas is a Python library for analysing tabular data. Its table is a DataFrame: rows and columns carry labels, and each column stores data of its own type.
Typical pandas tasks: read a table from a file or database, remove missing values and duplicates, compute summary figures, join several tables and write out the result. The data must fit in memory; for larger datasets the documentation suggests processing a file in chunks (chunksize) or using a library with distributed computing. A shared table that several programs read and write belongs in a database: pandas keeps its structures in memory and is not designed for concurrent writes.
How a DataFrame is built
A DataFrame is a two-dimensional table, like a SQL table: row labels form the index, and columns have names. Each column is a separate one-dimensional Series with its own data type (dtype): integers, strings and dates are stored differently. You reach a cell by label with loc or by position with iloc.
Column operations are vectorised: df["amount"] * 1.2 multiplies the whole column at once, with no loop over rows. If two tables have different row labels, pandas aligns them first: values are matched by label, and labels missing on one side produce the missing value NaN. The label-to-value link is preserved in every operation unless you break it manually.
Copy-on-Write: a selection gives a copy
Since pandas 3.0, Copy-on-Write applies: the result of any selection behaves as a copy, and changing it does not affect the original table. There is one rule: you can only modify the object itself. To write a value into the original DataFrame, apply loc to it directly, in a single operation with row labels and a column name.
A typical workflow
import pandas as pd # read the table into memorydf = pd.read_csv("data.csv")# look at the first rowsprint(df.head())# select rows with large amountsbig = df[df["amount"] > 500]# group and sum the amounts by citysummary = big.groupby("city")["amount"].sum()# write the resultsummary.to_csv("summary.csv")Each step has its own section: reading and writing files is covered in “Reading and writing data”, selecting rows and columns in “Selection and filtering: loc, iloc, masks”, grouping in “Grouping: groupby”, and joining tables in “Joining tables: merge and concat”.
How pandas differs from NumPy
pandas is built on NumPy and works with its arrays, but for tabular data the differences show immediately.
| Feature | pandas (DataFrame) | NumPy (ndarray) |
|---|---|---|
| Labels | rows and columns are labelled: access by label and by position | only integer positions, no names |
| Column types | each column has its own dtype | one dtype for the whole array |
| Missing values | a dedicated missing value, NaN | no missing value for integers: a column with NaN becomes floating-point |
| Alignment | operations match values by label | operations work by position, element by element |
| Resizing | columns and rows can be added and removed | size is fixed at creation |
| Data shape | a table of columns; a Series is one column | an array of any dimensionality |
Use a NumPy array for uniform numeric computations without labels; once the data is heterogeneous or you need to select by column name, a DataFrame is more convenient. If you know SQL: pandas operations mirror SELECT, GROUP BY and JOIN — see the correspondence table in the SQL reference, section “SELECT: selecting, filtering and sorting”.
What you need to know first
- Python basics: variables, lists and dictionaries, functions, loops — see the Python reference, sections “Syntax and control flow” and “Built-in types and data structures”.
- Project environments and package installation:
venvandpip— see the Python reference, section “Modules, packages and dependencies”. - The command line: running a script, changing directory — see the Bash reference.
Section sources
the section is written from these pages- Package overviewpandas.pydata.org/pandas-docs/version/3.1/getting_started/overview.html(opens in a new tab)
- Intro to data structurespandas.pydata.org/pandas-docs/version/3.1/user_guide/dsintro.html(opens in a new tab)
- Frequently Asked Questions (FAQ)pandas.pydata.org/pandas-docs/version/3.1/user_guide/gotchas.html(opens in a new tab)
- Comparison with SQLpandas.pydata.org/pandas-docs/version/3.1/getting_started/comparison/comparison_with_sql.html(opens in a new tab)