Python Pandas TimedeltaIndex.ceil
Python是一种进行数据分析的伟大语言,主要是因为以数据为中心的Python包的奇妙生态系统。Pandas就是这些包中的一个,它使导入和分析数据变得更加容易。
Pandas TimedeltaIndex.ceil()函数将TimedeltaIndex对象的索引ceil到指定的freq。该函数将频率作为一个参数,我们希望对其进行取值。
语法: TimedeltaIndex.ceil(freq)
参数 :
freq : freq string/object
返回:相同类型的索引
示例#1:使用TimedeltaIndex.ceil()函数将给定的TimedeltaIndex对象的值上限为指定频率。
# importing pandas as pd
import pandas as pd
# Create the first TimedeltaIndex object
tidx = pd.TimedeltaIndex(start ='1 days 02:00:12.001124', periods = 5,
freq ='N', name ='Koala')
# Print the TimedeltaIndex object
print(tidx)
输出 :
现在,我们将使用TimedeltaIndex.ceil()函数将该值削成微小的频率。
# ceil the values to minutely frequency.
tidx.ceil('T')
输出 :
正如我们在输出中看到的,TimedeltaIndex.ceil()函数已经返回了一个新的索引对象,其中包含了以所需频率为上限的数值。
示例#2:使用TimedeltaIndex.ceil()函数将给定的TimedeltaIndex对象的值上限为指定频率。
# importing pandas as pd
import pandas as pd
# Create the TimedeltaIndex object
tidx = pd.TimedeltaIndex(data =['06:05:01.000030', '+23:59:59.999999',
'22 day 2 min 3us 10ns', None])
# Print the TimedeltaIndex object
print(tidx)
输出 :
现在,我们将使用TimedeltaIndex.ceil()函数将该值截断为每日频率。
# ceil the values to daily frequency.
tidx.ceil('D')
输出 :
正如我们在输出中看到的,TimedeltaIndex.ceil()函数已经返回了一个新的索引对象,其中包含了以所需频率为上限的数值。