Python Pandas DatetimeIndex.day_name()

Python Pandas DatetimeIndex.day_name()

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

Pandas DatetimeIndex.day_name()函数返回DateTimeIndex的日期名称和指定的语言环境。默认的locale是None,在这种情况下,名字会以英文返回。

语法: DatetimeIndex.day_name(locale=None)

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

返回:日名的索引

示例#1:使用DatetimeIndex.day_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 Pandas DatetimeIndex.day_name()

现在,我们要返回法语区的日期名称。

# return the names of the days in French
didx.day_name(locale ='French')

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

让我们把日子的名字用英语回报给大家

# return the names of the days in English
didx.day_name(locale ='English')

输出 :
Python Pandas DatetimeIndex.day_name()

示例#2:使用DatetimeIndex.day_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 Pandas DatetimeIndex.day_name()

现在,我们要返回德语区的日期名称。

# return the names of the days in German
didx.day_name(locale ='German')

输出 :
Python Pandas DatetimeIndex.day_name()
正如我们在输出中看到的,该函数返回了一个Index对象,其中包含了德国地区的日期名称。

Python教程

Java教程

Web教程

数据库教程

图形图像教程

大数据教程

开发工具教程

计算机教程