Create and display a one-dimensional array-like object using Pandas in Python

Series() is a function present in the Pandas library that creates a one-dimensional array and can hold any type of objects or data in it. In this article, let us learn the syntax, create and display one-dimensional array-like object containing an array of data using Pandas library.

pandas.Series()

Syntax : pandas.Series(parameters)
Parameters :

  • data : Contains data stored in Series.
  • index : Values must be hashable and have the same length as data.
  • dtype : Data type for the output Series.
  • name : The name to give to the Series.
  • copy : Copy input data.

Returns : An object of class Series

Example 1 : Creating Series from a list

filter_none

edit
close

play_arrow

link
brightness_4
code

# import the library
import pandas as pd
  
# create the one-dimensional array
data = [1, 2, 3, 4, 5]
  
# create the Series
ex1 = pd.Series(data)
  
# displaying the Series
print(ex1)

chevron_right


Output :



Example 2 :Creating a Series from a NumPy array.

filter_none

edit
close

play_arrow

link
brightness_4
code

# import the pandas and numpy library
import pandas as pd
import numpy as np
  
# create numpy array
data = np.array(['a', 'b', 'c', 'd'])
  
# create one-dimensional data
s = pd.Series(data)
  
# display the Series
print(s)

chevron_right


Output :

Example 3: Creating a Series from a dictionary.

filter_none

edit
close

play_arrow

link
brightness_4
code

# import the pandas library
import pandas as pd
  
# create dictionary
dict = {'a' : 0.1, 'b' : 0.2, 'c' : 0.3}
  
# create one-dimensional data
s = pd.Series(dict)
  
# display the Series
print(s)

chevron_right


Output :

Example 4 :Creating a Series from list of lists.

filter_none

edit
close

play_arrow

link
brightness_4
code

# importing the module
import pandas as pd
  
# creating the data
data = [['g', 'e', 'e', 'k', 's'],
        ['f', 'o', 'r'],
        ['g', 'e', 'e', 'k', 's']]
  
# creating a Pandas series of lists
s = pd.Series(data)
  
# displaying the Series
print(s)

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

Blockchain Enthusiast

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.