How can I include datetimes into pd.DataFrame?
import pandas as pd
from datetime import datetime
df = pd.DataFrame({"a": ['2002-02-02', '2002-02-03', '2002-02-04']})
df["b"] = df["a"].apply(lambda t: datetime.strptime(t, '%Y-%m-%d')) # datetime.strptime returns datetime.datetime
print(datetime(2002, 2, 2) in df["b"])
outputs False.
Similarly,
f["c"] = df["b"].apply(lambda t: t.to_pydatetime())
print(datetime(2002, 2, 2) in df["c"])
outputs False.
Note that neither this nor this works. Following any of those approaches, I end up with Timestamps instead of datetimes in the data frame.
I am using Python 3.8.5 and Pandas 1.2.1.