python pandas datetime format code example Example: format date field in pandas df['date'] = pd.to_datetime(df["date"].dt.strftime('%Y-%m'))