
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Python Pandas - Check if an element belongs to an Interval
To check if an element belongs to an Interval, use the in property. At first, import the required libraries −
import pandas as pd
Create a time interval
interval = pd.Interval(left=0, right=10)
Display the interval
print("Interval...\n",interval)
Check for the existence of an element in an Interval
print("\nThe specific element exists in the Interval? = \n",6 in interval)
Example
Following is the code
import pandas as pd # Create a time interval interval = pd.Interval(left=0, right=10) # display the interval print("Interval...\n",interval) # display the interval length print("\nInterval length...\n",interval.length) # check for the existence of an element in an Interval print("\nThe specific element exists in the Interval? = \n",6 in interval)
Output
This will produce the following code
Interval... (0, 10] Interval length... 10 The specific element exists in the Interval? = True
Advertisements