Pandas

Pandas Series

01 · Learning Path File · Pandas Series · 1 of 12

Learning Path

Python Basics → List / Dictionary → NumPy → Pandas → Data Cleaning → EDA → Visualization → Machine Learning

Pandas is the next step after NumPy when working with real-world tabular data.

02 · What is a Series? File · Pandas Series · 2 of 12

What is a Series?

A Series is a one-dimensional labeled array in Pandas.

It can hold any data type (integers, strings, floats, Python objects, etc.).

Think of a Series as a single column of data with an index.

Python
import pandas as pd
Always import pandas as pd. This is the standard convention.
03 · Creating a Series File · Pandas Series · 3 of 12

Creating a Series

Python
s = pd.Series([10, 20, 30, 40])
print(s)
Output
0    10
1    20
2    30
3    40
dtype: int64
By default, Pandas creates an integer index starting from 0.
04 · Custom Index File · Pandas Series · 4 of 12

Creating Series with Custom Index

Python
s = pd.Series(
    [85, 92, 78, 90],
    index=["Arun", "Priya", "Rahul", "Sneha"]
)
print(s)
Output
Arun     85
Priya    92
Rahul    78
Sneha    90
dtype: int64
Now each value has a meaningful label instead of just 0, 1, 2, 3.
05 · From Dictionary File · Pandas Series · 5 of 12

Create Series from Dictionary

Python
data = {"Arun": 85, "Priya": 92, "Rahul": 78, "Sneha": 90}
s = pd.Series(data)
print(s)
Output
Arun     85
Priya    92
Rahul    78
Sneha    90
dtype: int64
The dictionary keys become the index, and the values become the data.
06 · Basic Attributes File · Pandas Series · 6 of 12

Important Attributes

Python
print(s.values)     # actual data
print(s.index)      # index labels
print(s.dtype)      # data type
print(s.shape)      # shape
print(s.size)       # number of elements
print(s.name)       # name of the Series
Output
[85 92 78 90]
Index(['Arun', 'Priya', 'Rahul', 'Sneha'], dtype='object')
int64
(4,)
4
None
values gives the data as a NumPy array.
index gives the labels.
dtype tells the data type of the values.
07 · Accessing Elements File · Pandas Series · 7 of 12

Accessing Elements

Python
# By position
print(s[0])
print(s[1:3])

# By label
print(s["Priya"])
print(s[["Arun", "Sneha"]])
Output
85
Priya    92
Rahul    78
dtype: int64
92
Arun     85
Sneha    90
dtype: int64
You can access elements either by position (integer location) or by label (index name).
08 · Vectorized Operations File · Pandas Series · 8 of 12

Vectorized Operations

You can perform operations on the entire Series without writing loops.

Python
print(s + 5)
print(s * 2)
print(s > 80)
Output
Arun     90
Priya    97
Rahul    83
Sneha    95
dtype: int64

Arun     170
Priya    184
Rahul    156
Sneha    180
dtype: int64

Arun      True
Priya     True
Rahul    False
Sneha     True
dtype: bool
These operations are fast because they are powered by NumPy underneath.
09 · Filtering File · Pandas Series · 9 of 12

Filtering a Series

Python
# Students who scored more than 80
print(s[s > 80])
Output
Arun     85
Priya    92
Sneha    90
dtype: int64
Boolean filtering is one of the most powerful features of Pandas Series.
10 · Missing Values (NaN) File · Pandas Series · 10 of 12

Missing Values (NaN)

NaN means Not a Number — it represents a missing value.

Python
marks = pd.Series([85, 92, None, 88, 95])
print(marks)
Output
0    85.0
1    92.0
2     NaN
3    88.0
4    95.0
dtype: float64
When you use None in a numeric Series, Pandas automatically converts it to NaN.
11 · Handling Missing Data File · Pandas Series · 11 of 12

Handling Missing Data

Check for missing values

Python
print(marks.isnull())
print(marks.notna())
print(marks.isnull().sum())   # count of missing values
Output
0    False
1    False
2     True
3    False
4    False
dtype: bool

0     True
1     True
2    False
3     True
4     True
dtype: bool

1
True is treated as 1 and False as 0 when we use .sum() on boolean Series.

Remove missing values

Python
print(marks.dropna())
Output
0    85.0
1    92.0
3    88.0
4    95.0
dtype: float64
dropna() returns a new Series without the missing values. Original Series remains unchanged.

Fill missing values

Python
print(marks.fillna(0))
Output
0    85.0
1    92.0
2     0.0
3    88.0
4    95.0
dtype: float64
fillna(0) replaces all NaN values with 0.
12 · Summary File · Pandas Series · 12 of 12

Summary

  • A Series is a one-dimensional labeled array.
  • It is the building block of a DataFrame.
  • You can create it from a list, dictionary, or NumPy array.
  • Supports vectorized operations and filtering.
  • Handles missing data using isnull(), dropna(), and fillna().
Home Pandas Series

Pandas Series

Master the one-dimensional labeled array — the foundation of data analysis with Pandas.

Select any topic from the left sidebar to begin.


Start Learning →