Thursday 31 August 2023

How to Get the Number of Elements in a Pandas Series?

Series ‘size’ attribute return the number of elements in a series. For example, ‘primes_series.size’ return the number of elements in the series.

 

count_elements_in_a_series.py

import pandas as pd

primes = [2, 3, 5]
primes_index = ['first_prime', 'second_prime', 'third_prime']
primes_series = pd.Series(primes, index=primes_index, name='Hold the Prime numbers')

print('Total elements in the primes_series : ', primes_series.size)

Output

Total elements in the primes_series :  3

  

Previous                                                 Next                                                 Home

No comments:

Post a Comment