Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

converting string to datetime pandas

df['date_col'] = pd.to_datetime(df['date_col'], format='%Y-%m-%d %H:%M:%S')

%Y - Year as decimal number (2004)
%m - month as zero padded number (03)
%d - Day of the month (16)
%H - Hour in 24 hour format
%M - Minutes (16)
%S - Seconds (03)

For more formats visit - https://docs.python.org/3/library/datetime.html#strftime-and-strptime-behavior

Add other characters to match the exact format of the date
as given in your dataset (':', '-' etc)
 
PREVIOUS NEXT
Tagged: #converting #string #datetime #pandas
ADD COMMENT
Topic
Name
6+9 =