I'm trying to convert a column in a dataframe to timeseries, the values in the column are strings and they are in the following form: 12/10/202110:42:05.397 which means 12-10-2021 at 10:42:05 and 397 milliseconds. This is the format that Labview is saving the data into a file. I'm trying to use the following command, but I can't figure out how to define the format for my case: pd.to_datetime(df.DateTime, format=???) Note that there is no space between year 2021 and hour 10
CodePudding user response:
Use:
df['dt'] = pd.to_datetime(df['DateTime'], format='%d/%m/%Y%H:%M:%S.%f')
print(df)
# Output
DateTime dt
0 12/10/202110:42:05.397 2021-10-12 10:42:05.397
Setup:
df = pd.DataFrame({'DateTime': ['12/10/202110:42:05.397']})
As suggested by @RaymondKwok, use the documentation: