Python | Pandas Index.contains ()
Python - отличный язык для анализа данных, в первую очередь из-за фантастической экосистемы пакетов Python, ориентированных на данные. Pandas - один из таких пакетов, который значительно упрощает импорт и анализ данных.
Pandas Index.contains() function return a boolean indicating whether the provided key is in the index. If the input value is present in the Index then it returns True else it returns False indicating that the input value is not present in the Index.
Syntax: Index.contains(key)
Parameters :
Key : ObjectReturns : boolean
Example #1: Use Index.contains() function to check if the given date is present in the Index.
# importing pandas as pdimport pandas as pd # Creating the Indexidx = pd.Index(["2015-10-31", "2015-12-02", "2016-01-03", "2016-02-08", "2017-05-05"]) # Print the Indexidx |
Выход :
Let’s check if ‘2016-02-08’ is present in the Index or not.
# Check if input date in present or not.idx.contains("2016-02-08") |
Output :
As we can see in the output, the function has returned True indicating that the value is present in the Index.
Example #2: Use Index.contains() function to check if the input month is present in the Index or not.
# importing pandas as pdimport pandas as pd # Creating the Indexidx = pd.Index(["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]) # Print the Indexidx |
Выход :
Let’s check if ‘May’ is present in the Index or not
# to check if the input month is# part of the Index or not.idx.contains("May") |
Выход :
Внимание компьютерщик! Укрепите свои основы с помощью базового курса программирования Python и изучите основы.
Для начала подготовьтесь к собеседованию. Расширьте свои концепции структур данных с помощью курса Python DS. А чтобы начать свое путешествие по машинному обучению, присоединяйтесь к курсу Машинное обучение - базовый уровень.