I have been looking for this answer in the community so far, could not have.
I have a dataframe in python 3.5.1 that contains a column with dates in string imported from
For most common date and datetime formats, pandas .to_datetime
function can parse them without we providing format.
For example:
df.TimeStamp.apply(lambda x: pd.to_datetime(x))
And in the example given from the question,
df['TimeStamp'] = pd.to_datetime(df['TimeStamp']).dt.strftime('%m/%d/%Y %H:%M:%S')
will give us the same result.
Using .apply
will be efficient if you have multiple columns.
Of course, providing the parsing format is necessary for many situations. For a full list of formats, please see https://docs.python.org/3/library/datetime.html.