I'm trying to change the format of a datetime column in my Dataframe using lambda and strftime like below
df['Date Column'] = df['Date Column'].map(lambda x: x.strftime('%m/%d/%Y'))
However, since I have null values in some of these fields, this is giving me an error. I cannot drop these null rows because I still need them for the data in the other columns. Is there a way around this error without dropping the nulls.
Perhaps something like
df['Date Column'].map(lambda x: x.strftime('%m/%d/%Y') if x != null else "")
?
The method I've used is to drop the nulls, format the column, then merge it back onto the original dataset, but this seems like a very inefficient method.