Thursday 31 August 2023

How to Get the Shape of a Pandas Series?

Series ‘shape’ attribute return the shape of the Series (number of rows, number of columns).

get_shape.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('primes_series shape : ', primes_series.shape)

 

Output

primes_series shape :  (3,)

 

Previous                                                 Next                                                 Home

No comments:

Post a Comment