Python | Pandas Series.asobject

Python Methods and Functions

Series.asobject Pandas Series.asobject returns an array of object type data. It converts the row data to an array of object type.

Syntax: Series.asobject

Parameter: None

Returns: array of objects

Example # 1: Use the Series.asobject attribute to return a series of objects containing the boxed value for this Series object.

# import pandas as pd

import pandas as pd

 
# Create series

sr = pd.Series ([ `First` , `Second` , ` Third` , `Fourth` ])

 
# Print series

print (sr)

Output:

Now we will use the Series.asobject to convert the series to an object type array.

# to return the series as an object
sr.asobject

Output:


As we can see from the output, the Series. asobject successfully returned an array objects.

Example # 2: Use the Series.asobject attribute to return a series of objects containing the packed value for this Series object.

# import pandas as pd

import pandas as pd

 
# Create a series

sr = pd.Series ([ `Sam` , 21 , `Alisa` , 18 , `Sophia` , 19 , `Max` , 17 ])

 
# Print series

print (sr)

Output:

We will now use the Series.asobject attribute to convert the series to an object type array.

# to return series as object
sr.asobject

Output:

As we can see from the output, the Attribute Series.asobject successfully returned an array of objects.





Get Solution for free from DataCamp guru