Data Analysis with pandas · pandas Fundamentals

DataFrames and Series

Create and inspect DataFrames and Series: shape, dtypes, head, info and describe, and how columns are Series that share an index.

Create a free account to save this page, take notes and track your progress. Sign in

What you'll build

A small orders table as a DataFrame, inspected the way you'd inspect any new dataset: its size, column types, first rows and summary statistics. Every example in this course runs in your browser (click Run): it uses pandas 3 in Pyodide, exactly as when the outputs below were produced.

The idea

  • A DataFrame is a table: rows with an index (labels) and named columns. Each column is a Series, a one-dimensional array with the same index.
  • Every column has a dtype: int64, float64, bool, datetime64[us] (dates; microsecond resolution is the pandas 3 default when parsing), and in pandas 3 the dedicated str dtype for text.
  • Inspect first: shape, dtypes, head(), info() and describe() reveal the size, types, missing values and ranges before any analysis.

The code

Inspect a new datasetTry it yourself
from io import StringIO
import pandas as pd

csv = StringIO("""order_id,date,customer,country,product,quantity,unit_price
1001,2026-01-03,ana,DE,mug,2,8.50
1002,2026-01-03,ben,US,teapot,1,24.00
1003,2026-01-04,chen,DE,kettle,1,31.90
1004,2026-01-05,ana,DE,teapot,1,24.00
1005,2026-01-07,dara,FR,mug,4,8.50
1006,2026-01-07,ben,US,mug,1,8.50
""")
orders = pd.read_csv(csv, parse_dates=["date"])

print(orders.shape)
print(orders.dtypes)
print(orders.head(3))
print(orders.describe().loc[["mean", "min", "max"], ["quantity", "unit_price"]])

Output

(6, 7)
order_id               int64
date          datetime64[us]
customer                 str
country                  str
product                  str
quantity               int64
unit_price           float64
dtype: object
   order_id       date customer country product  quantity  unit_price
0      1001 2026-01-03      ana      DE     mug         2         8.5
1      1002 2026-01-03      ben      US  teapot         1        24.0
2      1003 2026-01-04     chen      DE  kettle         1        31.9
      quantity  unit_price
mean  1.666667   17.566667
min   1.000000    8.500000
max   4.000000   31.900000

A column is a Series; operations on it work element by element (vectorised), with no loop:

Columns are SeriesTry it yourself
from io import StringIO
import pandas as pd

csv = StringIO("""order_id,date,customer,country,product,quantity,unit_price
1001,2026-01-03,ana,DE,mug,2,8.50
1002,2026-01-03,ben,US,teapot,1,24.00
1003,2026-01-04,chen,DE,kettle,1,31.90
1004,2026-01-05,ana,DE,teapot,1,24.00
1005,2026-01-07,dara,FR,mug,4,8.50
1006,2026-01-07,ben,US,mug,1,8.50
""")
orders = pd.read_csv(csv, parse_dates=["date"])

quantity = orders["quantity"]
print(type(quantity).__name__, quantity.dtype)
revenue = orders["quantity"] * orders["unit_price"]
print(revenue.round(2).tolist())
print("total revenue:", revenue.sum())
print(orders["country"].value_counts())

Output

Series int64
[17.0, 24.0, 31.9, 24.0, 34.0, 8.5]
total revenue: 139.4
country
DE    3
US    2
FR    1
Name: count, dtype: int64

Common mistakes

  • Starting analysis without checking dtypes: numbers stored as text sort and add wrongly.
  • Looping over rows with for instead of vectorised column operations.
  • Confusing the index with a column; reset_index() and set_index() move data between them.

Key points

  • A DataFrame is a table of Series that share an index.
  • Check shape, dtypes, head and describe before analysing.
  • Column operations are vectorised: no loops needed.

Further reading: 10 minutes to pandas · Intro to data structures

Practice questions

What is the relationship between a DataFrame and a Series?

Answer

A DataFrame is a table whose columns are Series sharing the same index; selecting one column returns a Series.

Why check dtypes right after loading data?

Answer

Wrong types (numbers or dates read as text) silently break sorting, maths and grouping; dtypes show what pandas inferred.

What does describe() show?

Answer

Summary statistics for numeric columns: count, mean, standard deviation, min, quartiles and max.

Open in the app to mark lessons complete, take notes and track your progress.

Was this page helpful?