Skip to content

Series and DataFrames

A Series is a labeled 1D array. Think of it as a single spreadsheet column: every value has a matching row label sitting to its left, called the index.

Create a Series
import pandas as pd
 
s = pd.Series([10, 20, 30], name="scores")
print(s)
Series with explicit index
import pandas as pd
 
s = pd.Series([10, 20, 30], index=["a", "b", "c"], name="scores")
print(s)
print("Index:", s.index)

A DataFrame is a labeled 2D table — literally a dictionary of Series that all share the same row index. That’s why every column can have a different dtype, but df.index is one shared set of row labels for the whole table.

DataFrame from dict
import pandas as pd
 
df = pd.DataFrame({
    "name": ["Asha", "Ravi", "Meera"],
    "age": [23, 28, 26],
    "city": ["Pune", "Delhi", "Bengaluru"],
})
 
print(df)
DataFrame from records
import pandas as pd
 
rows = [
    {"name": "Asha", "age": 23, "city": "Pune"},
    {"name": "Ravi", "age": 28, "city": "Delhi"},
]
 
df = pd.DataFrame(rows)
print(df)
  • df.index labels rows
  • df.columns labels columns
Index and columns
import pandas as pd
 
df = pd.DataFrame({"a": [1, 2], "b": [3, 4]})
print("index:", df.index)
print("columns:", df.columns)

Pandas stores each column using a data type (dtype).

Check dtypes
import pandas as pd
 
df = pd.DataFrame({
    "age": [20, 21, 22],
    "score": [90.5, 88.0, 91.0],
    "passed": [True, True, False],
})
 
print(df.dtypes)
  • A numeric column can become object if it contains mixed types like "N/A".
  • Dates start as strings unless you parse them.

We’ll fix these issues later in the phase.

A Series is a single labeled column; a DataFrame stacks several Series side by side that all share the same row index.

diagram Series vs DataFrame mermaid
A DataFrame is a collection of Series that all share one row index.
sketch Series index → value, DataFrame columns p5.js
A Series pairs each index label with one value; a DataFrame is several Series lined up on a shared index.

Continue to Data Inspection (head, tail, info, describe) to quickly get oriented with any new dataset you load.

pch.coffeeTagline

pch.coffeeCta

pch.feedbackHeading

pch.feedbackSubheading