0

Hi just noticed some weird behaviour of the "in" function for a pandas data frame.

I have two columns of dates in a feedTable pandas data table, the index and a column called 'date_forecast_adjusted'. I need to shift some dates around depending if the dates are already in the two columns. It seems i can easily check if a shifted date is in the index, however for the column the "in" command doesn't seem to work.

I tried the following commands:

(datePD + i*timedelta(hours=24))
Timestamp('2015-12-28 00:00:00')

pd.to_datetime("28/12/2015",dayfirst=True)
Timestamp('2015-12-28 00:00:00')

feedTable[feedTable['date_forecast_adjusted']==
pd.to_datetime("28/12/2015",dayfirst=True)]['date_forecast_adjusted'][0]
Timestamp('2015-12-28 00:00:00')

feedTable[feedTable['date_forecast_adjusted']==(datePD + 
i*timedelta(hours=24))]['date_forecast_adjusted'][0]
Timestamp('2015-12-28 00:00:00')

feedTable[feedTable['date_forecast_adjusted']==
pd.to_datetime("28/12/2015",dayfirst=True)]['date_forecast_adjusted'][0]==
(datePD + i*timedelta(hours=24))
True

(datePD + i*timedelta(hours=24)) in feedTable['date_forecast_adjusted']
False

pd.to_datetime("28/12/2015",dayfirst=True) in 
feedTable['date_forecast_adjusted']
False

pd.to_datetime("28/12/2015",dayfirst=True) in 
feedTable[feedTable['date_forecast_adjusted']==
pd.to_datetime("28/12/2015",dayfirst=True)]['date_forecast_adjusted']
False

pd.Series((datePD + 
i*timedelta(hours=24))).isin(feedTable['date_forecast_adjusted'])
0    True

any(feedTable['date_forecast_adjusted'] ==
(datePD + i*timedelta(hours=24)) )
True

I would say weird behavior from the in function...

0 Answers0