Series basics
A Series is a single labelled column of data: values plus an index that names each one.
In this page:
Syntax
s = pd.Series([value1, value2, value3], index=[label1, label2, label3])
Series basics
A Series is a one-dimensional array with an index. If you do not supply an index it uses 0, 1, 2 and so on. It holds one dtype and supports fast vectorized maths.
Note:
A DataFrame column is itself a Series.
Example: Series basics
import pandas as pd
s = pd.Series([90, 85, 70], index=["math", "art", "music"])
print(s)
print("art:", s["art"])
print(s * 2)
# Output:
# math 90
# art 85
# music 70
# dtype: int64
# art: 85
# math 180
# art 170
# music 140
# dtype: int64
Related Topics
Common Mistakes
- Forgetting the index labels exist
- Assuming a Series behaves exactly like a list
- Mixing types and getting object dtype
Chapter Summary
- A Series is values plus an index
- The default index is 0..n-1
- It holds one dtype
- Maths is vectorized
🔒
Chapter Quiz — Complete all 7 topics to unlock
0/7 topics done
Complete these topics first: