Python Pandas DatetimeIndex.week

Python Pandas DatetimeIndex.week

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

Pandas DatetimeIndex.week属性为DatetimeIndex对象的每个条目输出周的序数值。它与DatetimeIndex.week属性类似。

语法: DatetimeIndex.week

返回:索引对象

示例#1:使用DatetimeIndex.week属性来查找DatetimeIndex对象中每个条目的周的序号值。

# importing pandas as pd
import pandas as pd
  
# Create the DatetimeIndex
# Here 'W' represents Weekly frequency
didx = pd.DatetimeIndex(start ='2000-01-10 06:30', freq ='W',
                            periods = 3, tz ='Asia/Calcutta')
  
# Print the DatetimeIndex
print(didx)
Python

输出 :
Python Pandas DatetimeIndex.week

现在我们要为DatetimeIndex对象中的每个条目找到一周的序数值。

# find the ordinal value of the week
# for each entries present in the object
didx.week 
Python

输出 :
Python Pandas DatetimeIndex.week
正如我们在输出中所看到的,该函数返回了一个Index对象,其中包含了DatetimeIndex对象中每个条目中存在的周的序数值。

例子2:使用DatetimeIndex.week属性来查找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)
Python

输出 :
Python Pandas DatetimeIndex.week

现在我们要为DatetimeIndex对象中的每个条目找到一周的序数值。

# find the ordinal value of the week 
# for each entries present in the object
didx.week
Python

输出 :
Python Pandas DatetimeIndex.week
正如我们在输出中所看到的,该函数返回了一个Index对象,其中包含了DatetimeIndex对象中每个条目中存在的周的序数值。

Python教程

Java教程

Web教程

数据库教程

图形图像教程

大数据教程

开发工具教程

计算机教程

Pandas 日期时间

登录

注册