1

I'm a little lost. I have a dataframe with a column names dates, that looks like this:

>>> dates_df
    product   tile       date
0       L30  34JDN 2019-01-01
1       L30  34JDN 2019-01-10
2       L30  34JDN 2019-01-17
3       L30  34JDN 2019-01-26
4       L30  34JDN 2019-02-02
..      ...    ...        ...
175     L30  34JEP 2019-11-17
176     L30  34JEP 2019-11-26
177     L30  34JEP 2019-12-03
178     L30  34JEP 2019-12-12
179     L30  34JEP 2019-12-28

I also have a single object of <class 'datetime.date'> that looks like this:

>>> date_np
datetime.date(2019, 1, 1)

When I get the first element of the column date with dates_df["date"][0] it gives me: Timestamp('2019-01-01 00:00:00').

How can I make this timestamp and my date_np-object comparable so that this would run

dates_df[dates_df["date"] == date_np], because at the moment it gives me back an empty dataframe.

Empty DataFrame
Columns: [product, tile, date]
Index: []

Lenn
  • 1,283
  • 7
  • 20

1 Answers1

1

Use Series.dt.date for compare by scalar dates:

dates_df[dates_df["date"].dt.date == date_np]

Or convert scalar to datetime:

dates_df[dates_df["date"] == datetime(date_np.year, date_np.month, date_np.day)]
jezrael
  • 822,522
  • 95
  • 1,334
  • 1,252