Convert a NumPy array to a Pandas series

Let us see how to convert a NumPy array to a Pandas series. A NumPy array can be converted into a Pandas series by passing it in the pandas.Series() function.

Example 1 :

filter_none

edit
close

play_arrow

link
brightness_4
code

# importing the modules
import numpy as np
import pandas as pd
  
# creating an NumPy array
array = np.array([10, 20, 1, 2
                   3, 4, 5, 6, 7])
  
# displaying the NumPy array
print("Numpy array is :")
display(array)
  
# converting the NumPy array 
# to a Pandas series
series = pd.Series(array) 
  
# displaying the Pandas series
print("Pandas Series : ")
display(series)

chevron_right


Output :

Example 2 :

filter_none

edit
close

play_arrow

link
brightness_4
code

# importing the modules
import numpy as np
import pandas as pd
  
# creating an NumPy array
array = np.random.rand(5
  
# displaying the NumPy array
print("Numpy array is :")
display(array)
  
# converting the NumPy array 
# to a Pandas series
series = pd.Series(array) 
  
# displaying the Pandas series
print("Pandas Series : ")
display(series)

chevron_right


Output :

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.


Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.