Add two Series

Add two Series

EasyPandas Programs · 3 of 95

Write a pandas program to add two Series.

Input
[1, 6, 9, 5], [5, 2, 4, 5]
Output
[6, 8, 13, 10]

Approach

  1. + adds values with the same index.

Solution

Python
import pandas as pda, b = pd.Series([1, 6, 9, 5]), pd.Series([5, 2, 4, 5])print((a + b).tolist())
Output
[6, 8, 13, 10]

Learn the concept

New to this topic? Read the lesson, then come back.

More pandas programs

← All 95 Pandas Programs

Series to list

Series to list

EasyPandas Programs · 2 of 95

Write a pandas program to convert a Series to a list and print its type.

Output
[15, 43, 88] list

Approach

  1. tolist().

Solution

Python
import pandas as pditems = pd.Series([15, 43, 88]).tolist()print(items, type(items).__name__)
Output
[15, 43, 88] list

Learn the concept

New to this topic? Read the lesson, then come back.

More pandas programs

← All 95 Pandas Programs

Create a Series

Create a Series

EasyPandas Programs · 1 of 95

Write a pandas program to create and display a one-dimensional Series.

Input
[15, 43, 88, 23]
Output
0    15
1    43
2    88
3    23
dtype: int64

Approach

  1. pd.Series(list); pandas adds an index 0, 1, 2, …

Solution

Python
import pandas as pds = pd.Series([15, 43, 88, 23])print(s)
Output
0    15
1    43
2    88
3    23
dtype: int64

Learn the concept

New to this topic? Read the lesson, then come back.

More pandas programs

← All 95 Pandas Programs

Python Pandas Programs with Solutions

Python Practice › Pandas Programs

Python Pandas Programs with Solutions

95 programs95 easy0 medium0 hard

95 pandas programs: Series arithmetic and statistics, building and filtering DataFrames, sorting, adding and renaming columns, string methods, joining tables and handling missing values. Outputs come from pandas 3; the in-browser Try it uses an older pandas, so some printouts (such as column types) may differ slightly.

Before you start

Read the Pandas lesson first if the topic is new to you.

All programs