1

Getting future warning in pandas when comparing python datetime with dates in pandas. Not sure how to do this conversion.

        date1 = datetime.date(year, month, 1)
        date2 = datetime.date(year, month, days)
        dd = df.loc[df['Date'].between(date1, date2), ['Col1','Col2', 'Col3','Col4','Col5']]
        r = rowpos[month]
/home/user/.local/lib/python3.6/site-packages/pandas/core/series.py:3658:

FutureWarning: Comparing Series of datetimes with 'datetime.date'. Currently, the 'datetime.date' is coerced to a datetime. In the future pandas will not coerce, and a TypeError will be raised. To retain the current behavior, convert the 'datetime.date' to a datetime with 'pd.Timestamp'. lmask = self >= left

oppsig
  • 181
  • 1
  • 8
  • Have you tried, as suggested, `pd.Timestamp(datetime.date(year, month, 1))` ? – jpp Jun 22 '18 at 22:39
  • 1
    That worked excellent. If i wanted to create a timestamp for today, do i need to do it with datetime and then convert? like "today = pd.Timestamp(datetime.date.today())" or can i create it directly with pandas? – oppsig Jun 22 '18 at 22:47
  • Just use `pd.Timestamp('today')` or, if you want to zero out time, `pd.Timestamp('today').normalize()`. – jpp Jun 22 '18 at 23:12

0 Answers0