I'm doing a data transformation and I need to run a while
between date periods, but I have the error:
"TypeError: Can not compare type 'Timestamp' with type 'str'"
I have seen with type()
what type of data they are and both are class 'pandas.tslib.Timestamp'
therefore I do not understand what happens.
I enclose my complete code so you can see it and a CSV file so that you can run it and perform the test:
from collections import defaultdict
import pandas as pd
from datetime import datetime, timedelta
from time import time
fecha_i=[]
fecha_f=[]
contador=[]
id=[]
contador={}
contador = defaultdict(list)
df = pd.read_csv('contour-export-2017-12-14.csv', header=0, sep=',',parse_dates = ['FCH_HORA_INICIO'],dayfirst = True, usecols=[0,3,6,7])
fecha_i=df['FCH_HORA_INICIO']
fecha_f=df['FCH_HORA_TERMINO']
id=df['ID']
acumulado=fecha_i[0]
i=1
k=0
print(type(acumulado))
print(type(fecha_i[0]))
while(acumulado<datetime.now()):
acumulado=fecha_i[0]+timedelta(days=i)
k=0
while k<=len(df)-1:
if acumulado>=fecha_i[k] and acumulado<=fecha_f[k]:
contador[acumulado].append(str(ID[k]))
k=k+1
else:
k=k+1
i=i+1
File: link