Python Pandas DatetimeIndex.day
Python是一种进行数据分析的伟大语言,主要是因为以数据为中心的Python包的奇妙生态系统。Pandas就是这些包中的一个,它使导入和分析数据变得更加容易。
Pandas DatetimeIndex.day属性会输出一个Index对象,其中包含DatetimeIndex对象的每个条目中的日期。
语法: DatetimeIndex.day
返回:包含天数的索引。
示例#1:使用DatetimeIndex.day属性来查找DatetimeIndex对象中存在的天数。
# importing pandas as pd
import pandas as pd
# Create the DatetimeIndex
# Here the 'W' represents Weekly frequency
didx = pd.DatetimeIndex(start ='2014-08-01 10:00', freq ='W',
periods = 5, tz ='Asia/Calcutta')
# Print the DatetimeIndex
print(didx)
输出 :
现在我们要找到DatetimeIndex对象中存在的所有日期值。
# find all the days present in the object
didx.day
输出 :
正如我们在输出中看到的,该函数返回了一个Index对象,其中包含与DatetimeIndex对象中每个条目的天数对应的天数值。
示例#2:使用DatetimeIndex.day属性来查找DatetimeIndex对象中存在的天数。
# importing pandas as pd
import pandas as pd
# Create the DatetimeIndex
# Here the 'M' represents Month end frequency
didx = pd.DatetimeIndex(start ='2014-08-01 10:00', freq ='M',
periods = 5, tz ='Asia/Calcutta')
# Print the DatetimeIndex
print(didx)
输出 :
现在我们要找到DatetimeIndex对象中存在的所有日期值。
# find all the months in the object
didx.day
输出 :
正如我们在输出中看到的,该函数返回了一个Index对象,其中包含与DatetimeIndex对象中每个条目的天数对应的天数值。