Home > front end >  Stfrtime with 'D' inside String
Stfrtime with 'D' inside String

Time:01-13

How can you deal with a random string inside a datetime string when parsing using pandas?

I have some timestamps of the form

enter image description here

Which I try to match with this '%Y-%m-%d %H:%M:%S:%f'

(Why they have a 'D' instead of a 'T' is uncertain - they're not durations!)

When I try to parse them using Pandas, I get this error

TypeError: Unrecognized value type: <class 'str'>

I am confident the dataset is consistent in form.

Is there a correct way to do this?

I realise I can replace the 'D' with 'T' but keeping the original form of the data is crucial for this piece of work.

CodePudding user response:

If need original form with D and type datetimes/Timestamp, it is impossible in python.

If need convert column to datetimes - replace not necessary if specify format with D and . before %f:

df = pd.DataFrame({'date':['2022-12-01D07:52:52.04700000',
                           '2022-12-01D07:52:52.04700000']})

df['date'] = pd.to_datetime(df['date'], format='%Y-%m-           
  • Related