Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags


How to use Series.any() function in pandas

Maria Elijah

The Series.any() function in pandas

The Series.any() function in pandas checks whether any element in a given Series is True, across the specified axis.


Series.any(axis=0, bool_only=None, skipna=True, level=None)


  • axis: This represents the axis in which the operation is to be performed.

  • bool_only: This includes only boolean values.

  • skipna: This parameter is used to skip NaN values. The default is True.

  • level: The default is None. It represents the level to be broadcasted (in the case of multilevel).

Code example

The following code will demonstrate how to use the Series.any() function in pandas.

import pandas as pd
import numpy as np
# create Series 
num_series  = pd.Series([np.nan, 1, 0, 4,np.nan, 2])
# using Series.any()
Series.any() function in Python

Code explanation

  • Lines 1–2: We import the libraries pandas and numpy.

  • Line 4: We create the num_series series.

  • Lines 7: We check for any true value in the Series using the any() function.



View all Courses

Keep Exploring