2

I am trying to create a column to retrieve only month stat from Trade Trade Dt column.

I want format MMM below to be a number.

map_cat['Trade Month'] = pd.DatetimeIndex(map_cat['Trade Trade Dt']).month
ted
  • 13,596
  • 9
  • 65
  • 107
Wei Chen
  • 57
  • 6
  • Welcome to StackOverflow. Please take the time to read this post on [how to provide a great pandas example](https://stackoverflow.com/questions/20109391/how-to-make-good-reproducible-pandas-examples) as well as how to provide a [minimal, Complete, and Verifiable example](https://stackoverflow.com/help/mcve) and revise your question accordingly. These tips on how to ask a good question may also be useful. – yatu Feb 24 '20 at 15:02
  • Try [`strftime`](https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.Series.dt.strftime.html) – Dan Feb 24 '20 at 15:04

2 Answers2

2

Another option:

map_cat['Trade Month'] = pd.DatetimeIndex(map_cat['Trde Trade Dt']).month_name().str[:3]
Quang Hoang
  • 146,074
  • 10
  • 56
  • 74
1

Use strftime with %b

map_cat['Trade Month'] = pd.DatetimeIndex(map_cat['Trde Trade Dt']).strftime('%b')
Scott Boston
  • 147,308
  • 15
  • 139
  • 187