Posts

Showing posts from November 25, 2018

How to set missing Year, Month and Day for Panda's Datetime

Image
up vote 1 down vote favorite I have timestamp data in the format %H:%M:%S:%f . When I read it and pass it into a dataframe with pd.to_datetime it will automatically fill in 01/01/1900 in addition to the properly passed %H:%M:%S:%f How can I set it to a specific year, month, day while reading it and passing it the hour, minute, second, millisecond data? Code I'm using: import pandas as pd df = pd.DataFrame({'Time': ["00:00:00:001", "00:00:00:005","00:00:00:009"]}) df['Time'] = pd.to_datetime(df['Time'], format='%H:%M:%S:%f') print(df) Output: Time 0 1900-01-01 00:00:00.001 1 1900-01-01 00:00:00.005 2 1900-01-01 00:00:00.009 Desired output: A set date, so for instance: Time 0 2018-11-21 00:00:00.001 1 20