我想要一个带有时间戳列的pandas DataFrame,并希望创建一个只有月份的列.我希望月份列包含月份的字符串表示,而不是整数.我做过这样的事情:
df['Dates'] = pd.to_datetime(df['Dates'])
df['Month'] = df.Dates.dt.month
df['Month'] = df.Month.apply(lambda x: datetime.strptime(str(x), '%m').strftime('%b'))
Run Code Online (Sandbox Code Playgroud)
然而,这是一种蛮力方法,并不是非常高效.有没有更优雅的方法将月份的整数表示转换为字符串表示?