Home » Pandas DataFrame.where()

Pandas DataFrame.where()

by Online Tutorials Library

Pandas DataFrame.where()

The main task of the where() method is to check the data frame for one or more conditions and return the result accordingly. By default, if the rows are not satisfying the condition, it is filled with NaN value.

Syntax

Parameters

  • cond: It refers to one or more conditions to check the data frame.
  • other: It replaces the rows that do not satisfy the condition with the user-defined object; the default value is NaN.
  • inplace: Returns the boolean value. If the value is true, it makes the changes in the dataframe itself.
  • axis: An axis to check( row or columns).

Returns

Example1

Output

     A        B  0   True     True  1   True     True  2   True     True  3   True     True  4   True     True  

You may also like