Python Pandas DatetimeIndex.month_name()

Python Pandas DatetimeIndex.month_name()

Python是一种进行数据分析的伟大语言,主要是因为以数据为中心的Python包的奇妙生态系统。Pandas就是这些包中的一个,它使导入和分析数据变得更加容易。

Pandas DatetimeIndex.month_name()函数返回DateTimeIndex在指定locale下的月份名称。默认的locale是None,在这种情况下,名字会以英文返回。

语法: DatetimeIndex.month_name(locale=None)

参数 :
locale :locale决定用什么语言来返回月份名称。

返回:月份名称的索引

示例#1:使用DatetimeIndex.month_name()函数来返回DatetimeIndex对象中每个条目的月份名称。返回法语区的月份名称

# importing pandas as pd
import pandas as pd
  
# Create the DatetimeIndex
# Here 'Q' represents quarterly frequency 
didx = pd.DatetimeIndex(start ='2018-11-15 09:45:10', freq ='Q', periods = 5)
  
# Print the DatetimeIndex
print(didx)
Python

输出 :
Python Pandas DatetimeIndex.month_name()

现在,我们要返回法语区的月份名称。

# return the names of the month in French
didx.month_name(locale ='French')
Python

输出 :
Python Pandas DatetimeIndex.month_name()
正如我们在输出中看到的,该函数返回了一个Index对象,其中包含了法语中的月份名称。

示例#2:使用DatetimeIndex.month_name()函数来返回DatetimeIndex对象中每个条目的月份名称。返回德语区的月份名称

# importing pandas as pd
import pandas as pd
  
# Create the DatetimeIndex
# Here 'M' represents monthly frequency 
didx = pd.DatetimeIndex(start ='2015-03-02', freq ='M', periods = 5)
  
# Print the DatetimeIndex
print(didx)
Python

输出 :
Python Pandas DatetimeIndex.month_name()

现在我们要返回德国地区的月份名称。

# return the names of the month in German
didx.month_name(locale ='German')
Python

输出 :
Python Pandas DatetimeIndex.month_name()
正如我们在输出中所看到的,该函数返回了一个Index对象,其中包含了德国语言中的月份名称。

Python教程

Java教程

Web教程

数据库教程

图形图像教程

大数据教程

开发工具教程

计算机教程

Pandas 日期时间

登录

注册