-1

I have data stored in a JSON file and am reading it in with Pandas. The format of the time is 'Jun 10, 2021, 01:05:30:565'. I would like to present the time column with its match. However, python gives this error: Unknown string format:', 'Jun 10, 2021, 01:05:30:565 AM').

I used: DS [pd.to_datetime(day + ' ' + time)] = value

That line worked with other columns that have time : HH:MM: SS. but with milliseconds I'm unable to present what I want.

Brad Solomon
  • 38,521
  • 31
  • 149
  • 235
Doaa A
  • 3
  • 2
  • Welcome @DoaaA. Please add a [minimal, reproducible example](https://stackoverflow.com/help/minimal-reproducible-example) to your question, thank you. – fbardos Jul 16 '21 at 12:04

1 Answers1

0

From your example :

>>> import pandas as pd

>>> df = pd.DataFrame({'date': ['Jun 10, 2021, 01:05:30:565 AM']}, 
...                   index = [0]) 
>>> df
    date
0   Jun 10, 2021, 01:05:30:565 AM

We can convert the date column to DateTime like so :

>>> df['date'] = pd.to_datetime(df['date'], format="%b %d, %Y, %H:%M:%S:%f %p")
>>> df
    date
0   2021-06-10 01:05:30.565
tlentali
  • 3,407
  • 2
  • 14
  • 21