Reputation: 1
I have a dataframe with Date_Birth in the following format: July 1, 1991 (as type object). How can I change the entire column to datetime?
Thanks
Upvotes: 0
Views: 1353
Reputation: 77407
Use the pandas.to_datetime
function. You can write out a format specifier in the strptime
format or have python guess the format. In your case, guessing works.
>>> import pandas as pd
>>> df=pd.DataFrame({"Date":["July 1, 1991"]})
>>> pd.to_datetime(df["Date"], format="%B %d, %Y")
0 1991-07-01
Name: Date, dtype: datetime64[ns]
>>> pd.to_datetime(df["Date"], infer_datetime_format=True)
0 1991-07-01
Name: Date, dtype: datetime64[ns]
Upvotes: 1