1

I'm working with a little dataframe it has a column with dates. I'm trying to rename the column but I get de following error: TypeError: 'list' object is not callable, anyone knows what am I doing wrong? The code is the following:

import pandas as pd
from datetime import datetime, timedelta

inicio = datetime(2017,10,1)
fin    = datetime(2017,10,5)


lista_fechas = [(inicio + timedelta(days=d)).strftime("%Y-%m-%d")
                    for d in range((fin - inicio).days + 1)] 
print(lista_fechas)

df = pd.DataFrame(data=lista_fechas)
df1 = df.rename(columns=['0', 'Fecha'])
FObersteiner
  • 22,500
  • 8
  • 42
  • 72

1 Answers1

1

rename can't be used like that, why not just use:

import pandas as pd
from datetime import datetime, timedelta

inicio = datetime(2017,10,1)
fin    = datetime(2017,10,5)


lista_fechas = [(inicio + timedelta(days=d)).strftime("%Y-%m-%d")
                    for d in range((fin - inicio).days + 1)] 
print(lista_fechas)

df = pd.DataFrame(data=lista_fechas, columns=['Fecha'])

If you still want to use rename try:

df = pd.DataFrame(data=lista_fechas, columns=['Fecha'])
df1 = df.rename(columns = {0:'Fecha'}) 
U13-Forward
  • 69,221
  • 14
  • 89
  • 114