transform '2022-02-02' to pd.datetime in python

To transform '2022-02-02' to pd.datetime in Python, you can use the pd.to_datetime() function provided by the pandas library. Here's an example:

main.py
import pandas as pd

date_str = '2022-02-02'
datetime_obj = pd.to_datetime(date_str)

print(datetime_obj)
106 chars
7 lines

Output:

main.py
2022-02-02 00:00:00
20 chars
2 lines

By using pd.to_datetime(), the date string is converted to a pd.datetime object that represents the given date.

related categories

gistlibby LogSnag