Python Pandas DatetimeIndex.freq
Python是一种进行数据分析的伟大语言,主要是因为以数据为中心的Python包的奇妙生态系统。Pandas就是这些包中的一个,它使导入和分析数据变得更加容易。
Pandas DatetimeIndex.freq属性如果在DatetimeIndex对象中设置了频率,则返回频率对象。如果没有设置频率,则返回无。
语法: DatetimeIndex.freq
返回:频率对象
示例#1:使用DatetimeIndex.freq属性来查找给定DatetimeIndex对象的频率。
# importing pandas as pd
import pandas as pd
# Create the DatetimeIndex
# Here 'BQ' represents Business quarter frequency
didx = pd.DatetimeIndex(start ='2014-08-01 10:05:45', freq ='BQ',
periods = 5, tz ='Asia/Calcutta')
# Print the DatetimeIndex
print(didx)
输出 :
现在我们要为给定的DatetimeIndex对象找到频率的值。
# find the value of frequency
didx.freq
输出 :
正如我们在输出中看到的,该函数已经为给定的DatetimeIndex对象返回了一个频率对象。
示例#2:使用DatetimeIndex.freq属性来查找给定DatetimeIndex对象的频率。
# importing pandas as pd
import pandas as pd
# Create the DatetimeIndex
# Here 'CBMS' represents custom business month start frequency
didx = pd.DatetimeIndex(start ='2000-01-10 06:30', freq ='CBMS',
periods = 5, tz ='Asia/Calcutta')
# Print the DatetimeIndex
print(didx)
输出 :
现在我们要为给定的DatetimeIndex对象找到频率的值。
# find the value of frequency
didx.freq
输出 :
正如我们在输出中看到的,该函数为给定的DatetimeIndex对象返回了一个频率对象。didx DatetimeIndex对象具有自定义的业务月开始频率。