📜  Python| Pandas DatetimeIndex.weekofyear

📅  最后修改于: 2022-05-13 01:54:43.161000             🧑  作者: Mango

Python| Pandas DatetimeIndex.weekofyear

Python是一种用于进行数据分析的出色语言,主要是因为以数据为中心的Python包的奇妙生态系统。 Pandas就是其中之一,它使导入和分析数据变得更加容易。

Pandas DatetimeIndex.weekofyear属性为 DatetimeIndex 对象的每个条目输出一年中一周的序数值。

示例 #1:使用DatetimeIndex.weekofyear属性查找 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)

输出 :

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

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

输出 :

正如我们在输出中看到的那样,该函数返回了一个 Index 对象,其中包含 DatetimeIndex 对象的每个条目中存在的星期的序数值。示例 #2:使用DatetimeIndex.weekofyear属性查找 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 week
# for each entries present in the object
didx.weekofyear

输出 :

正如我们在输出中看到的那样,该函数返回了一个 Index 对象,其中包含 DatetimeIndex 对象的每个条目中存在的星期的序数值。