Python | Pandas Series.asobject

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.

filter_none

edit
close

play_arrow

link
brightness_4
code

# importing pandas as pd
import pandas as pd
  
# Creating the Series
sr = pd.Series(['First', 'Second', 'Third', 'Fourth'])
  
# Print the series
print(sr)

chevron_right


Output :

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

filter_none

edit
close

play_arrow

link
brightness_4
code

# to return the series as object
sr.asobject

chevron_right


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.

filter_none

edit
close

play_arrow

link
brightness_4
code

# importing pandas as pd
import pandas as pd
  
# Creating the Series
sr = pd.Series(['Sam', 21, 'Alisa', 18, 'Sophia', 19, 'Max', 17])
  
# Print the series
print(sr)

chevron_right


Output :

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

filter_none

edit
close

play_arrow

link
brightness_4
code

# to return the series as object
sr.asobject

chevron_right


Output :

As we can see in the output, the Series.asobject attribute has successfully returned an array of objects.



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.