'Pandas Datetime Format

I'm trying to convert 01/02/20(Thu)05:05:17 into DD-MM-YYYY format, but struggling through pandas.

df['_source.now'] = pd.to_datetime(df['_source.now'])

I get this error: ParserError: Unknown string format: 01/02/20(Thu)05:05:17



Solution 1:[1]

You can try this

# day first, use '%d/%m/%y(%a)%H:%M:%S'
# month first, use '%m/%d/%y(%a)%H:%M:%S'
pd.to_datetime(df['_source.now'],format='%m/%d/%y(%a)%H:%M:%S',errors='coerce').dt.strftime('%d-%m-%Y')

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Vae Jiang