9951 explained code solutions for 126 technologies


python-pandasHow to use datetime type


import pandas as pd

df = pd.DataFrame({
  'date_str': ['3/10/2022', '3/11/2022', '3/12/2021'],
  'value': [1,2,3]
})

df['date'] = pd.to_datetime(df['date_str'])ctrl + c
import pandas as pd

load Pandas module

pd.DataFrame

creates Pandas DataFrame object

.to_datetime(

convert given column values to datetime type (will automatically parse given strings)

date_str

string column with date

'date'

column with datetime type