Python Practice › Pandas Programs › Program 13

Series of lists to one Series

EasyPandas Programs · 13 of 95

Write a pandas program to turn a Series of lists into one flat Series.

Advertisement
Input
[["Sqa", "tool"], ["Learning", "python"], ["Is", "fun"]]
Output
0         Sqa
1        tool
2    Learning
3      python
4          Is
5         fun
dtype: str

Approach

  1. explode() puts each list item on its own row.

Solution

Python
import pandas as pds = pd.Series([["Sqa", "tool"], ["Learning", "python"], ["Is", "fun"]])print(s.explode().reset_index(drop=True))
Output
0         Sqa
1        tool
2    Learning
3      python
4          Is
5         fun
dtype: str
Advertisement

Learn the concept

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

More pandas programs

← All 95 Pandas Programs