Python: Pandas Rename Series Example


If in your Python pandas program, you have a Series as a one-dimensional labeled array holding one-dimensional data as below,

Pandas Series Example:

import pandas as pd

fifteen_series = pd.Series([10, 15, 20, 25, 30, 35], name='15_Series')
print(fifteen_series)
0    10
1    15
2    20
3    25
4    30
5    35
Name: 15_Series, dtype: int64

Now if you want to rename the series, you can make use of the Series.rename() function.


Example: Rename a series

import pandas as pd

fifteen_series = pd.Series([10, 15, 20, 25, 30, 35], name='15_Series')

fifteen_series = fifteen_series.rename('Fifteen Series')
print(fifteen_series)

Output:

0    10
1    15
2    20
3    25
4    30
5    35

Name: Fifteen Series, dtype: int64

Facing issues? Have Questions? Post them here! I am happy to answer!

Author Info:

Rakesh (He/Him) has over 14+ years of experience in Web and Application development. He is the author of insightful How-To articles for Code2care.

Follow him on: X

You can also reach out to him via e-mail: rakesh@code2care.org

Copyright ยฉ Code2care 2024 | Privacy Policy | About Us | Contact Us | Sitemap