How to swap months and days in a datetime object?

I have a columns in a pandas dataframe with dates as:

year, day, month , hour , minute, second

2015-09-03 14:32:00

I would like to turn this into

year, month, day, hour , minute, second

2015-03-09 14:32:00

Answer

You can apply a lambda to your dates and call datetime.strftime:

In [168]:
# create sample df
df = pd.DataFrame({'date':['2015-09-03 14:32:00']})
df['date'] = pd.to_datetime(df['date'])
df

Out[168]:
                 date
0 2015-09-03 14:32:00

In [171]:
import datetime as dt
# apply strftime
df['date'] = df['date'].apply(lambda x: dt.datetime.strftime(x, '%Y-%d-%m %H:%M:%S'))
df

Out[171]:
                  date
0  2015-03-09 14:32:00