Python Pandas TimedeltaIndex.contains

Python Pandas TimedeltaIndex.contains

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

Pandas TimedeltaIndex.contains()函数检查传递的标签是否存在于TimedeltaIndex对象中。它返回一个布尔值。如果传递的标签是存在的,那么它返回True,否则返回False。

语法: TimedeltaIndex.contains(key)
参数 :
key : object
返回 : 布尔值

示例#1:使用TimedeltaIndex.contains()函数来检查传递的标签是否存在于索引中。

# 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)
Python

输出 :

Python Pandas TimedeltaIndex.contains

现在我们将使用TimedeltaIndex.contains()函数来检查’1 days 02:00:12.001124’是否存在于tidx对象中。

# check if the passed label is present or not.
tidx.contains('1 days 02:00:12.001124')
Python

输出 :

Python Pandas TimedeltaIndex.contains

正如我们在输出中看到的,TimedeltaIndex.contains()函数返回了True,表明传递的标签存在于索引中。

示例#2:使用TimedeltaIndex.contains()函数来检查传递的标签是否存在于索引中。

# 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)
Python

输出 :

Python Pandas TimedeltaIndex.contains

现在我们将使用TimedeltaIndex.contains()函数来检查’1 days 02:00:12.0101124’是否存在于tidx对象中。

# check if the passed label is present or not.
tidx.contains('1 days 02:00:12.0101124')
Python

输出 :

Python Pandas TimedeltaIndex.contains

正如我们在输出中看到的,TimedeltaIndex.contains()函数返回了False,表明传递的标签不存在于索引中。

Python教程

Java教程

Web教程

数据库教程

图形图像教程

大数据教程

开发工具教程

计算机教程

Pandas 日期时间

登录

注册