1

I am unable to rename the column of a series:

tabla_paso4

Date            decay
2015-06-29    0.003559
2015-09-18    0.025024
2015-08-24    0.037058
2014-11-20    0.037088
2014-10-02    0.037098
Name: decay, dtype: float64

I have tried:

tabla_paso4.rename('decay_acumul')
tabla_paso4.rename(columns={'decay':'decay_acumul'}

I already had a look at the possible duplicate, however don't know why although applying :

tabla_paso4.rename(columns={'decay':'decay_acumul'},inplace=True)

returns the series like this:

Date
2015-06-29    0.003559
2015-09-18    0.025024
2015-08-24    0.037058
2014-11-20    0.037088
2014-10-02    0.037098
dtype: float64
JamesHudson81
  • 2,215
  • 4
  • 23
  • 42
  • Possible duplicate of [python: rename single column header in pandas dataframe](http://stackoverflow.com/questions/19758364/python-rename-single-column-header-in-pandas-dataframe) – Pedro Lobito Apr 28 '17 at 16:47

2 Answers2

1

It looks like your tabla_paso4 - is a Series, not a DataFrame.

You can make a DataFrame with named column out of it:

new_df = tabla_paso4.to_frame(name='decay_acumul')
MaxU - stand with Ukraine
  • 205,989
  • 36
  • 386
  • 419
0

Try

tabla_paso4.columns = ['Date', 'decay_acumul']

or

tabla_paso4.rename(columns={'decay':'decay_acumul'}, inplace=True)

What you were doing wrong earlier, is you missed the inplace=True part and therefore the renamed df was returned but not assigned.

I hope this helps!

Thanos
  • 2,472
  • 1
  • 16
  • 33