How can I change the name of a Series
object?
Asked
Active
Viewed 4.3k times
18
-
Now-a-days, [you can call the `rename()` function if you do not want to modify your existing Series](https://stackoverflow.com/a/55295478/4909087) (for purposes such as method chaining). – cs95 Mar 22 '19 at 08:24
4 Answers
27
You can do this by changing the name
attribute of your subs
object:
Assuming its name is 'Settle'
and you want to change it to, say, 'Unsettle'
, just update the name
attribute, like so:
In [16]: s = Series(randn(10), name='Settle')
In [17]: s
Out[17]:
0 0.434
1 -0.581
2 -0.263
3 -1.384
4 -0.075
5 -0.956
6 0.166
7 0.138
8 -0.770
9 -2.146
Name: Settle, dtype: float64
In [18]: s.name
Out[18]: 'Settle'
In [19]: s.name = 'Unsettle'
In [20]: s
Out[20]:
0 0.434
1 -0.581
2 -0.263
3 -1.384
4 -0.075
5 -0.956
6 0.166
7 0.138
8 -0.770
9 -2.146
Name: Unsettle, dtype: float64
In [21]: s.name
Out[21]: 'Unsettle'

cs95
- 379,657
- 97
- 704
- 746

Phillip Cloud
- 24,919
- 11
- 68
- 88
13
-
using .rename() is the best way if you ask me, although I wouldn't use inplace=True, but rather do: series_ = series_.rename('new_name') – Sander van den Oord Sep 24 '19 at 12:13
-
-
-
1Here's why you shouldn't use inplace=True: https://stackoverflow.com/a/59242208/3489155 – Sander van den Oord Dec 28 '20 at 14:58
0
I finally renamed my Series object to 'Desired_Name' as follows
# Let my_object be the pandas.Series object
my_object.name = 'Desired_Name'
Then the automatically generated name that now is read in the legend now is 'Desired_Name' against 'Settle' previously.