dataframe
A DataFrame is data structure for working with tabular data in Python. It’s a two-dimensional, size-mutable table with labeled axes (rows and columns). It can hold heterogeneous data, meaning that different columns can use different data types.
You can use a DataFrame to read data from common sources, such as CSV, Excel, SQL, and others, clean and transform it, compute statistics, and prepare results for visualization or modeling.
In pandas, the DataFrame class provides rich, vectorized operations and powerful indexing. You can select data by label with .loc and by index with .iloc. Many operations also align by index labels, which helps you combine or compute across datasets safely. It also includes convenient tools for representing and working with missing values.
Example
Here’s a quick example, which requires you to pip install pandas:
>>> import pandas as pd
>>> data = [
... {"item": "apple", "quantity": 3, "price": 0.5},
... {"item": "banana", "quantity": 5, "price": 0.3},
... {"item": "apple", "quantity": 2, "price": 0.55},
... ]
>>> # Create a DataFrame
>>> df = pd.DataFrame(data)
>>> df
item quantity price
0 apple 3 0.50
1 banana 5 0.30
2 apple 2 0.55
>>> # Vectorized column arithmetic
>>> df["total"] = df["quantity"] * df["price"]
>>> df
item quantity price total
0 apple 3 0.50 1.5
1 banana 5 0.30 1.5
2 apple 2 0.55 1.1
>>> # Label-based selection with .loc
>>> df.loc[df["item"] == "apple", ["quantity", "price"]]
quantity price
0 3 0.50
2 2 0.55
>>> # Grouping and aggregating
>>> df.groupby("item")["total"].sum()
item
apple 2.6
banana 1.5
Name: total, dtype: float64
Here, you create a pandas DataFrame from the input data, adds a total column with a vectorized computation, filters the rows where item == "apple" using .loc, and finally groups by item and sums total to get per-item totals.
Related Resources
Tutorial
The pandas DataFrame: Make Working With Data Delightful
In this tutorial, you'll get started with pandas DataFrames, which are powerful and widely used two-dimensional data structures. You'll learn how to perform basic operations with data, handle missing values, work with time-series data, and visualize data from a pandas DataFrame.
For additional information on related topics, take a look at the following resources:
By Leodanis Pozo Ramos • Updated Jan. 9, 2026