Create a Pandas Series from array

Pandas Series is a one-dimensional labelled array capable of holding any data type (integers, strings, floating point numbers, Python objects, etc.). It has to be remembered that unlike Python lists, a Series will always contain data of the same type.

Let’s see how to create a Pandas Series from the array.

Method #1:Create a series from array without index.

In this case as no index is passed, so by default index will be range(n) where n is array length.

filter_none

edit
close

play_arrow

link
brightness_4
code

# importing Pandas & numpy
import pandas as pd
import numpy as np
  
# numpy array
data = np.array(['a', 'b', 'c', 'd', 'e'])
  
# creating series
s = pd.Series(data)
print(s)

chevron_right


Output:



0    a
1    b
2    c
3    d
4    e
dtype: object

 
Method #2: Create a series from array with index.

In this case we will pass index as a parameter to the constructor.

filter_none

edit
close

play_arrow

link
brightness_4
code

# importing Pandas & numpy
import pandas as pd
import numpy as np
  
# numpy array
data = np.array(['a', 'b', 'c', 'd', 'e'])
  
# creating series
s = pd.Series(data, index =[1000, 1001, 1002, 1003, 1004])
print(s)

chevron_right


Output:

1000    a
1001    b
1002    c
1003    d
1004    e
dtype: object

Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.

To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course.

My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.