Saturday 26 August 2023

How to Get the Name of a Pandas Series

Using ‘name’ attribute, we can get the name of the series.

 

Example

primes_series = pd.Series(primes, index=primes_index, name='Hold the Prime numbers')

 

Above snippet sets the name to 'Hold the Prime numbers'. We can access the same with ‘primes_series.name’.

 

series_name.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 name : ', primes_series.name)

 

Output

primes_series name :  Hold the Prime numbers

 

Previous                                                 Next                                                 Home

No comments:

Post a Comment