# What is Python pandas any() and how does it work?

The `DataFrame.any()` function from the [Python library pandas](https://www.ionos.co.uk/digitalguide/websites/web-development/python-pandas/) is used to check if at least one value along a specified axis in a DataFrame evaluates to `True`.

## What is the syntax for pandas `any()`?

The basic syntax of the pandas `any()` function is straightforward. Here’s what it looks like:

```python
DataFrame.any(axis=0, bool_only=None, skipna=True)
```

Note The pandas `DataFrame.any()` function is similar to `numpy.any()` in the popular Python library *NumPy*.

### Important parameters for `any()`

The function accepts several parameters:

<table>
  <thead>
    <tr>
      <th><strong>Parameter</strong></th>
      <th><strong>Description</strong></th>
      <th><strong>Default Value</strong></th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td>`axis`</td>
      <td>Specifies whether the method is applied along rows (0 or index) or columns (1 or columns)</td>
      <td>0</td>
    </tr>
    <tr>
      <td>`skipna`</td>
      <td>Specifies whether to skip NaN (Not a Number) values</td>
      <td>`True`</td>
    </tr>
    <tr>
      <td>`bool_only`</td>
      <td>If `True`, only boolean columns will be considered</td>
      <td>`False`</td>
    </tr>
  </tbody>
</table>

## How to use pandas `DataFrame.any()`

### Example 1: Checking for `True` values in rows

The `any()` function is most commonly used to check if any of the rows in a DataFrame contain at least one value that evaluates to `True`. This can come in handy when validating conditions.

```python
import pandas as pd
# Defining a DataFrame with three columns and three rows
data = {
    'A': [0, 0, 0],
    'B': [True, False, False],
    'C': [False, False, False]
}
df = pd.DataFrame(data)
# Using the any() function to check if any values in the rows evaluate to True
result = df.any(axis=0)
print(result)
```

In the code above, pandas `DataFrame.any()` returns a series showing that only column B contains a value that evaluates to `True`. The output looks like this:

```none
A    False
B    True
C    False
dtype: bool
```

### Example 2: Checking for `True` values in columns

Similar to the first example, you can check if any column contains at least one `True` value by passing `axis=1` as a parameter:

```python
result = df.any(axis=1)
print(result)
```

The output shows that only the first row has a value that evaluates to `True`:

```none
0     True
1    False
2    False
dtype: bool
```

Note Indexing in programming always starts at 0. That’s why a 0 is used to represent the first row in the output.


This is a markdown version of: [https://www.ionos.co.uk/digitalguide/websites/web-development/python-pandas-dataframe-any/](https://www.ionos.co.uk/digitalguide/websites/web-development/python-pandas-dataframe-any/) for AI/LLM consumption.