The Wayback Machine - https://web.archive.org/web/20240809132818/https://www.geeksforgeeks.org/pandas-series-dt-month_name/
Open In App

Pandas Series dt.month_name() | Get Month Name From DateTime Series

Last Updated : 07 Feb, 2024
Comments
Improve
Suggest changes
Like Article
Like
Save
Share
Report
News Follow

Pandas dt.month_name() method returns the month names of the DateTimeIndex with specified locale.

Example

Python3




import pandas as pd
sr = pd.Series(['2012-12-31 08:45', '2019-1-1 12:30', '2008-02-2 10:30',
               '2010-1-1 09:25', '2019-12-31 00:00'])
  
idx = ['Day 1', 'Day 2', 'Day 3', 'Day 4', 'Day 5']
sr.index = idx
sr = pd.to_datetime(sr)
result = sr.dt.month_name(locale = 'English')
print(result)


Output

dt.month_name() method output

Syntax

Syntax: Series.dt.month_name(locale=None) 

Parameter 

  • locale : Locale determining the language in which to return the month name. Default is English locale. 

Returns: Index of month names

How to Get the Month Names from the DateTime Series

To get the names of the months from the DateTime objects in a Pandas Series we use the dt.month_name() method of the Pandas library in Python.

Let us understand it better with an example:

Example:

Use the Series.dt.month_name() function to return the month names of the underlying DateTime data in the given series object. Return the names of the month in French language.

Python3




# importing pandas as pd
import pandas as pd
  
# Creating the Series
sr = pd.Series(pd.date_range('2012-12-31 09:45', periods = 5, freq = 'Q',
                            tz = 'Europe / Berlin'))
  
# Creating the index
idx = ['Day 1', 'Day 2', 'Day 3', 'Day 4', 'Day 5']
  
# set the index
sr.index = idx
  
# Print the series
print(sr)


Output :

datetime series created

Now we will use the Series.dt.month_name() function to return the names of the month of each timestamp in the given series object.

Python3




# return month name in french
result = sr.dt.month_name(locale = 'French')
  
# print the result
print(result)


Output :

month names returned

As we can see in the output, the Series.dt.month_name() function has successfully returned the names of the month in the specified language.



Similar Reads

Pandas Series dt.month | Extract Month Part From DateTime Series
The dt.month attribute returns a NumPy array containing the month of the DateTime in the underlying data of the given Series object. Example C/C++ Code import pandas as pd sr = pd.Series(['2012-10-21 09:30', '2019-7-18 12:30', '2008-02-2 10:30', '2010-4-22 09:25', '2019-11-8 02:22']) idx = ['Day 1', 'Day 2', 'Day 3', 'Day 4', 'Day 5'] sr.index = id
2 min read
Python | Pandas DatetimeIndex.month_name()
Python is a great language for doing data analysis, primarily because of the fantastic ecosystem of data-centric python packages. Pandas is one of those packages and makes importing and analyzing data much easier. Pandas DatetimeIndex.month_name() function return the month names of the DateTimeIndex with specified locale. The default locale is None
2 min read
Pandas Series dt.dayofweek | Get Day of Week from DateTime Series in Pandas
Pandas dt.dayofweek attribute returns the day of the week from the given DateTime Series Object. It is assumed the week starts on Monday, which is denoted by 0, and ends on Sunday which is denoted by 6. Example: C/C++ Code import pandas as pd sr = pd.Series(['2012-10-21 09:30', '2019-7-18 12:30', '2008-02-2 10:30', '2010-4-22 09:25', '2019-11-8 02:
2 min read
Pandas Series dt.daysinmonth | Get Number of Days in Month in Pandas Series
The dt.daysinmonth attribute returns the number of days in the month for the given DateTime series object. Example C/C++ Code import pandas as pd sr = pd.Series(['2012-12-31', '2019-1-1 12:30', '2008-02-2 10:30', '2010-1-1 09:25', '2019-12-31 00:00']) idx = ['Day 1', 'Day 2', 'Day 3', 'Day 4', 'Day 5'] sr.index = idx sr = pd.to_datetime(sr) result
2 min read
Pandas Series dt.minute | Extract Minute from DateTime Series in Pandas
Pandas Series.dt.minute attribute returns a NumPy array containing the minutes of the DateTime in the underlying data of the given series object. Example C/C++ Code import pandas as pd sr = pd.Series(['2012-10-21 09:30', '2019-7-18 12:30', '2008-02-2 10:30', '2010-4-22 09:25', '2019-11-8 02:22']) idx = ['Day 1', 'Day 2', 'Day 3', 'Day 4', 'Day 5']
2 min read
Pandas Series dt.days_in_month | Get Total Number of Days in Month in Pandas
The Pandas dt.days_in_month attribute returns the total number of days in the month for the given Series object. Example C/C++ Code import pandas as pd sr = pd.Series(['2012-12-31', '2019-1-1 12:30', '2008-02-2 10:30', '2010-1-1 09:25', '2019-12-31 00:00']) idx = ['Day 1', 'Day 2', 'Day 3', 'Day 4', 'Day 5'] sr.index = idx sr = pd.to_datetime(sr) r
2 min read
Pandas Series dt.nanosecond | Get Nanoseconds From DateTime Series
Pandas dt.nanosecond attribute returns a NumPy array containing the nanosecond of the DateTime in the underlying data of the given series object.  Example C/C++ Code import pandas as pd sr = pd.Series(pd.date_range('2012-12-12 12:12', periods = 5, freq = '5N')) idx = ['Day 1', 'Day 2', 'Day 3', 'Day 4', 'Day 5'] sr.index = idx result = sr.dt.nanose
2 min read
Pandas Series dt.day | Extract Day Part from DateTime Series
Pandas dt.day attribute returns a NumPy array containing the day value of the DateTime in the underlying data of the given series object. Example C/C++ Code import pandas as pd sr = pd.Series(['2012-10-21 09:30', '2019-7-18 12:30', '2008-02-2 10:30', '2010-4-22 09:25', '2019-11-8 02:22']) idx = ['Day 1', 'Day 2', 'Day 3', 'Day 4', 'Day 5'] # set th
2 min read
Pandas Series dt.week | Extract Week Number from DateTime Series
Pandas dt.week attribute returns a NumPy array containing the week ordinal of the year in the underlying data of the given DateTime Series object. Example C/C++ Code import pandas as pd sr = pd.Series(['2012-10-21 09:30', '2019-7-18 12:30', '2008-02-2 10:30', '2010-4-22 09:25', '2019-11-8 02:22']) idx = ['Day 1', 'Day 2', 'Day 3', 'Day 4', 'Day 5']
2 min read
Pandas Series dt.tz_convert | Change Timezone in DateTime Series
The dt.tz_convert() method converts tz-aware DateTime Series object from one time zone to another. Example C/C++ Code import pandas as pd sr = pd.Series(pd.date_range('2012-12-31 00:00', periods = 5, freq = 'D', tz = 'US / Central')) idx = ['Day 1', 'Day 2', 'Day 3', 'Day 4', 'Day 5'] sr.index = idx result = sr.dt.tz_convert(tz = 'Europe / Berlin')
2 min read
three90RightbarBannerImg