Python Pandas DatetimeIndex.freqstr

Python Pandas DatetimeIndex.freqstr

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

Pandas DatetimeIndex.freqstr属性如果在DatetimeIndex对象中设置了频率对象,则将其作为字符串返回。如果没有设置频率,则返回无。

语法: DatetimeIndex.freqstr

返回:频率对象为字符串

示例#1:使用DatetimeIndex.freqstr属性为给定的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)
Python

输出 :
Python Pandas DatetimeIndex.freqstr
现在我们要为给定的DatetimeIndex对象找到频率的字符串值。

# find the value of frequency object as string
didx.freqstr
Python

输出 :
Python Pandas DatetimeIndex.freqstr
正如我们在输出中看到的,该函数为给定的DatetimeIndex对象返回了频率对象的字符串。BQ “代表商业季度,”DEC “表示从12月开始。

示例#2:使用DatetimeIndex.freqstr属性,为给定的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)
Python

输出 :
Python Pandas DatetimeIndex.freqstr

现在我们要为给定的DatetimeIndex对象找到频率的字符串值。

# find the value of frequency object as string
didx.freqstr
Python

输出 :
Python Pandas DatetimeIndex.freqstr
正如我们在输出中看到的,该函数为给定的DatetimeIndex对象返回了一个字符串的频率对象。didx DatetimeIndex对象具有自定义业务月的开始频率。

Python教程

Java教程

Web教程

数据库教程

图形图像教程

大数据教程

开发工具教程

计算机教程

登录

注册