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
# import the libraryimport pandas as pd # create the one-dimensional arraydata = [1, 2, 3, 4, 5] # create the Seriesex1 = pd.Series(data) # displaying the Seriesprint(ex1) |
Output :
Example 2 :Creating a Series from a NumPy array.
# import the pandas and numpy libraryimport pandas as pdimport numpy as np # create numpy arraydata = np.array(['a', 'b', 'c', 'd']) # create one-dimensional datas = pd.Series(data) # display the Seriesprint(s) |
Output :
Example 3: Creating a Series from a dictionary.
# import the pandas libraryimport pandas as pd # create dictionarydict = {'a' : 0.1, 'b' : 0.2, 'c' : 0.3} # create one-dimensional datas = pd.Series(dict) # display the Seriesprint(s) |
Output :
Example 4 :Creating a Series from list of lists.
# importing the moduleimport pandas as pd # creating the datadata = [['g', 'e', 'e', 'k', 's'], ['f', 'o', 'r'], ['g', 'e', 'e', 'k', 's']] # creating a Pandas series of listss = pd.Series(data) # displaying the Seriesprint(s) |
Output :


