Series.rename , I have not seen this, but you can use Series.rename if you do not want to modify the existing series.
s = pd.Series('x', index=range(5), name='myseries') s 0 x 1 x 2 x 3 x 4 x Name: myseries , dtype: object t = s.rename('foobar') t 0 x 1 x 2 x 3 x 4 x Name: foobar , dtype: object s.name # 'myseries' t.name # 'foobar'
But why work with a function?
Chain method. Itβs just more convenient to do
ser.method1().rename('foobar').method2().method3()
Vs
ser = ser.method1() ser.name = 'foobar' ser.method2().method3()
With rename you can create a smooth chain of function calls.
source share