Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Extract month name from date column pandas

i have a df

Name Date
A    2021-04-21
B    2021-03-21
C    2021-02-23
D    2021-03-22

and the dtype of Date is object

i want another column as

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Name Date         Month
A    2021-04-21   April
B    2021-03-21   March
C    2021-02-23   February
D    2021-03-22   January

Tried with

df['month'] = pd.DatetimeIndex(df['Date']).month

this is giving the number of the month but not the name.

>Solution :

Check this
https://pandas.pydata.org/docs/reference/api/pandas.Series.dt.month_name.html

df['month'] = pd.DatetimeIndex(df['Date']).month_name()
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading