1from datetime import datetime
2
3datetime_str = '09/19/18 13:55:26'
4
5datetime_object = datetime.strptime(datetime_str, '%m/%d/%y %H:%M:%S')
6
7print(type(datetime_object))
8print(datetime_object) # printed in default format
9
1date_str = '09-19-2018'
2
3date_object = datetime.strptime(date_str, '%m-%d-%Y').date()
4print(type(date_object))
5print(date_object) # printed in default formatting
6
1df['date_time']=pd.to_datetime(df['date_time'], format='%d-%m-%Y %H.%M.%S')
2#fomrat given in code should match the format of the feature
3#here--> df['date_time'][0]=10-03-2004 18.00.00
4#watchout for the blanks '-' '.'