Python | Pandas Index.any ()



Index.any() Pandas Index.any() checks if any of the elements in the index are true or not. Returns a single boolean value if no axis is specified. It returns true if any value in the index is true. It returns false if none of the values ​​in the index are true.

Note: it treats 0 as false .

Syntax: Index.any (* args, ** kwargs)

Parameters:
* args : These parameters will be passed to numpy.any
** kwargs: These parameters will be passed to numpy.any

Returns: any: bool or array_like (if axis is specified)
A single element array_like may be converted to bool.

Example # 1: Use Index.any () to check if all values ​​in the index are true.

# import pandas as pd

import pandas as pd

  
# Create index

df = pd.Index ([ 17 , 69 , 33 , 5 , 0 , 74 , 0 ])

  
# Print the data frame
df

Output:

Let`s check if any of values ​​in the index true or has all false values.

< / p>

# check for falsehood
# value present in the index

df. any ()

Output:

As we can see in the output, the function returned true, indicating that there is at least one true value in the index.

Example # 2: Use Index.any () to check if any value in the index is true or not.

# import pandas as pd

import pandas as pd

  
# Create index

df = pd.Index ([ 0 , 0 , 0 , 0 , 0 ])

 
# Print the data frame
df

Output:

Let`s check if which -either of the values ​​in the index true or has all false values.

< code class = "comments"> # check if it`s false
# value present in the index

df. any ()

Output: