How to create a pandas series from multiple numpy arrays?

Let’s say you have two numpy arrays as shown below:

a=np.array([1,2,3,4,5])
b=np.array([6,7,8,9,10])

Table of Contents

Problem :

You want a create a pandas series from multiple numpy arrays as shown below.

0
0 1
1 2
2 3
3 4
4 5
5 6
6 7
7 8
8 9
9 10

 

Solution:

Join the contents of the array and then add it as a Series

1. First, let’s join the arrays using any of these methods-

np.concatenate(), np.join() ,np.hstack, np.append()

 

2. Once that is done, simply convert this array to pandas Series.

import numpy as np
import pandas as pd

a=np.array([1,2,3,4,5])
b=np.array([6,7,8,9,10])

print(pd.Series(np.concatenate([a,b])))

 

Hope this helps!

Happy Pythoning!

If you enjoyed reading, share this article.

Anusha Pai is a Software Engineer having a long experience in the IT industry and having a passion to write. She has a keen interest in writing Python Errorfixes, Solutions, and Tutorials.

Leave a Comment