Python Pandas DatetimeIndex.dayofweek
Python是一种进行数据分析的伟大语言,主要是因为以数据为中心的Python包的奇妙生态系统。Pandas就是这些包中的一个,它使导入和分析数据变得更加容易。
Pandas DatetimeIndex.dayofweek属性为DatetimeIndex对象的每个条目输出星期的序数值。周一到周日的数值范围是0到6。
语法: DatetimeIndex.dayofweek
返回:索引对象
示例#1:使用DatetimeIndex.dayofweek属性来查找DatetimeIndex对象中每个条目的星期的序数值。
# importing pandas as pd
import pandas as pd
# Create the DatetimeIndex
# Here 'D' represents Daily frequency
didx = pd.DatetimeIndex(start ='2000-01-10 06:30', freq ='D',
periods = 3, tz ='Asia/Calcutta')
# Print the DatetimeIndex
print(didx)
输出 :
现在我们要为DatetimeIndex对象中的每个条目寻找星期的序数值。
# find the ordinal value of the day
# of the week for each entries present in the object
didx.dayofweek
输出 :
正如我们在输出中看到的,该函数返回了一个Index对象,其中包含了DatetimeIndex对象中每个条目的周天数的序数值。
例2:使用DatetimeIndex.dayofweek属性来查找DatetimeIndex对象中每个条目的星期的序数值。
# importing pandas as pd
import pandas as pd
# Create the DatetimeIndex
# Here 'M' represents monthly frequency
didx = pd.DatetimeIndex(start ='2014-08-01 10:05:45', freq ='M',
periods = 5, tz ='Asia/Calcutta')
# Print the DatetimeIndex
print(didx)
输出 :
现在我们要为DatetimeIndex对象中的每个条目寻找星期的序数值。
# find the ordinal value of the day of the week
# for each entries present in the object
didx.dayofweek
输出 :
正如我们在输出中看到的,该函数返回了一个Index对象,其中包含了DatetimeIndex对象中每个条目的周天数的序数值。