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