Python | Pandas Series.size

Python Methods and Functions

Pandas Series — it is a one-dimensional array with axis labels. Tags do not have to be unique, but must be hashable. The object supports indexing based on integers and labels and provides many methods for performing index-related operations.

Series.size Pandas Series.size returns the cardinality for objects in the series.

Syntax: Series.size

Parameter: None

Returns: size

Example # 1: Use the Series.size attribute to find the cardinality in the underlying data of a given series object.

# import pandas as pd

import pandas as pd

 
# Create series

sr = pd.Series ([ 'New York' , ' Chicago' , 'Toronto' , 'Lisbon' , 'Rio' ])

  
# Create row axis labels

sr.index = [ 'City 1' , ' City 2 ' , ' City 3' , 'City 4' , ' City 5'

 
# Print series

print (sr)

Output:

We will now use the Series.size attribute to find the cardinality in the underlying data of a given Series object.

# return the number of elements
sr.size

Output:

As we can see in the output, the Series.size attribute returned 5, which indicates that there are 5 elements in this series object.

Example # 2: Use the Series.size attribute to find the number of number of elements in the underlying data of this series object.

# import pandas as pd

import pandas as pd

 
# Create series

sr = pd.Series ([ '1/1 / 2018' , '2/1 / 2018' , ' 3/1 / 2018' , '4/1 / 2018' ])

 
# Create row axis labels

sr.index = [ ' Day 1' , 'Day 2' , 'Day 3' , ' Day 4' ]

 
# Print episode

print (sr)

Output:

We will now use the Series.size attribute to find the cardinality in the underlying data of this Series object.

# return the number of elements
sr.size

Output:

As we can see in the output, the Series.size attribute returned 4, indicating that this object has a series there are 4 elements.





Get Solution for free from DataCamp guru