I have a python dataframe. My column Date-Time
contains dates and times. Some are formatted as dates and some were typed in as strings.
Using python I want to skip cells that are of type str
and apply this function to the rest:
df['Date-Time'] = df['Date-Time'].apply(lambda x: x.strftime('%d/%m/%Y %H:%M:%S'))
is this possible?
CodePudding user response:
Try this way:
df['Date-Time'] = df['Date-Time'].apply(lambda x: x.strftime('%d/%m/%Y %H:%M:%S') if isinstance(x, datetime.date) else x)
This will format all date values and keep the others as they are