Python | Панды Index.all ()
Python - отличный язык для анализа данных, в первую очередь из-за фантастической экосистемы пакетов Python, ориентированных на данные. Pandas - один из таких пакетов, который значительно упрощает импорт и анализ данных.
Pandas Index.all() function checks if all the elements in the index are true or not. It returns one single boolean value if axis is not specified. It returns true if each individual value in the index are true. It returns false if any of the values in the index is not true.
Примечание: 0 рассматривается как ложное значение.
Syntax: Index.all(*args, **kwargs)
Parameters :
*args : These parameters will be passed to numpy.all
**kwargs : These parameters will be passed to numpy.allReturns : all : bool or array_like (if axis is specified)
A single element array_like may be converted to bool.
Example #1: Use Index.all() function to check if all values are true in the index.
# importing pandas as pdimport pandas as pd # Creating the Indexdf = pd.Index([10, 44, 5, 25, 74]) # Print the Indexdf |
Выход :
Let’s check if all the values in the index are true or not.
# to check if index values are true or notdf.all() |
Выход :
Как видно из выходных данных, функция вернула истину, что означает, что все значения в индексе верны.
Example #2: Use Index.all() function to check if all the values are true in the index. In the index we are having some 0 values.
# importing pandas as pdimport pandas as pd # Creating the Indexdf = pd.Index([17, 69, 33, 5, 0, 74, 0]) # Print the dataframedf |
Выход :
Let’s check if all the values in the index are true or it is having any false values as well.
# to check if there is any false # value present in the indexdf.all() |
Выход :
Внимание компьютерщик! Укрепите свои основы с помощью базового курса программирования Python и изучите основы.
Для начала подготовьтесь к собеседованию. Расширьте свои концепции структур данных с помощью курса Python DS. А чтобы начать свое путешествие по машинному обучению, присоединяйтесь к курсу Машинное обучение - базовый уровень.