osdir.com


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

format number is not recognized in a cycle


Diego Avesani wrote:

> Dear Peter, Deal all,
> 
> Trying different options, I manage this solution:
> 
>    mask = (df['datatime'] > str(start_date[ii])) & (df['datatime'] <= 
>    str(end_date[ii]))
> 
> As you can notice, I have put str before start_date[ii]) and end_date[ii].
> 
> What do you think?

Don't use your workaround unless you have ensured that 
you get the correct result. Comparisons between arbitrary types are 
dangerous in Python 2:

>>> "10" > 1
True
>>> "1" > 1
True
>>> "0" > 1
True

Perhaps you can find a better approach when you  post your problem in a 
forum dedicated to pandas.