dachu darshan
dachu darshan

Reputation: 35

change timestamp format pandas

Example dataHow to change the timestamp format which has the format of '2019-12-16-12-40-53' and I want it to convert to '2019-12-16 12:40:53'

I tried

    df['timeStamp'] = df['timeStamp'].apply(lambda x: 
                                dt.datetime.strptime(x,'%Y%b%d:%H:%M:%S'))

and I got the error

    ValueError: time data '2019-12-16-12-40-53' does not match format '%Y%b%d:%H:%M:%S'

I am attaching an image of data that I am using as timestamp.

Upvotes: 1

Views: 2756

Answers (1)

jezrael
jezrael

Reputation: 863166

Use to_datetime and change format with %m for match months in numbers with - between parts of datetimes:

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

Upvotes: 4

Related Questions