Python is a great language for doing data analysis, primarily because of the fantastic ecosystem of data-centric python packages. Pandas is one of those packages and makes importing and analyzing data much easier.
Pandas Series.asobject attribute returns an array of object data type. It converts the series data into an array of object type.
Syntax:Series.asobject
Parameter : None
Returns : array of objects
Example #1: Use Series.asobject attribute to return object series containing boxed value for the given Series object.
# importing pandas as pdimport pandas as pd # Creating the Seriessr = pd.Series(['First', 'Second', 'Third', 'Fourth']) # Print the seriesprint(sr) |
Output :

Now we will use Series.asobject attribute to convert the series into an array of object type.
# to return the series as objectsr.asobject |
Output :

As we can see in the output, the Series.asobject attribute has successfully returned an array of objects.
Example #2 : Use Series.asobject attribute to return object series containing boxed value for the given Series object.
# importing pandas as pdimport pandas as pd # Creating the Seriessr = pd.Series(['Sam', 21, 'Alisa', 18, 'Sophia', 19, 'Max', 17]) # Print the seriesprint(sr) |
Output :

Now we will use Series.asobject attribute to convert the series into an array of object type.
# to return the series as objectsr.asobject |
Output :

As we can see in the output, the Series.asobject attribute has successfully returned an array of objects.
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. And to begin with your Machine Learning Journey, join the Machine Learning – Basic Level Course


