Python|熊猫 DatetimeIndex.month_name()
Python是一种用于进行数据分析的出色语言,主要是因为以数据为中心的Python包的奇妙生态系统。 Pandas就是其中之一,它使导入和分析数据变得更加容易。
Pandas DatetimeIndex.month_name()
函数返回具有指定语言环境的 DateTimeIndex 的月份名称。默认语言环境是 None 在这种情况下,名称以英语返回。
Syntax: DatetimeIndex.month_name(locale=None)
Parameters :
locale : locale determining the language in which to return the month name
Return : Index of month names
示例 #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)
输出 :
现在我们要返回法语语言环境中的月份名称。
# return the names of the month in French
didx.month_name(locale ='French')
输出 :
正如我们在输出中看到的,该函数返回了一个 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)
输出 :
现在我们要返回德语语言环境中的月份名称。
# return the names of the month in German
didx.month_name(locale ='German')
输出 :
正如我们在输出中看到的,该函数返回了一个 Index 对象,其中包含德语语言环境中的月份名称。