Pandas DataFrame all() Method

Rate this post


Before any data manipulation can occur, two (2) new libraries will require installation.

  • The Pandas library enables access to/from a DataFrame.
  • The NumPy library supports multi-dimensional arrays and matrices in addition to a collection of mathematical functions.

To install these libraries, navigate to an IDE terminal. At the command prompt ($), execute the code below. For the terminal used in this example, the command prompt is a dollar sign ($). Your terminal prompt may be different.

$ pip install pandas

Hit the <Enter> key on the keyboard to start the installation process.

$ pip install numpy

Hit the <Enter> key on the keyboard to start the installation process.

If the installations were successful, a message displays in the terminal indicating the same.

Feel free to view the PyCharm installation guide for the required libraries.

Add the following code to the top of each code snippet. This snippet will allow the code in this article to run error-free.

import pandas as pd
import numpy as np 

DataFrame all()

The all() method determines if all elements over a specified axis resolve to True.

The syntax for this method is as follows:

DataFrame.all(axis=0, bool_only=None, skipna=True, level=None, **kwargs)
axisIf zero (0) or index is selected, apply to each column. Default 0.
If one (1) apply to each row.
bool_onlyIncludes only Boolean DataFrame columns. If None, this parameter will attempt to use everything. Not supported for Series.
skipnaThis parameter excludes NaN/NULL values.
If the row/column is NaN and skipna=True, the result is True. For an empty row/column and skipna=False, then NaN is treated as True because they are not equal to 0.
levelIf the axis is MultiLevel, count along with a specific level and collapse into a Series.
**kwargsAdditional keywords have no effect.

For this example, the Rivers Clothing Warehouse Manager needs to find out what is happening with the inventory for Tanks. Something is amiss!

Code – Example 1

df_inv = pd.DataFrame({'Tops':     [36, 23, 19],
                       'Tanks':    [0, 0, -20],
                       'Pants':    [61, -33, 67],
                       'Sweats':   [88, 38, 13]})

result = df_inv.Tanks.all(skipna=False)
  • Line [1] creates a DataFrame from a Dictionary of Lists and saves it to df_inv.
  • Line [2] checks all elements of Tanks and saves True/False to the result variable.
  • Line [3] outputs the result to the terminal.



In the above example, we used Tanks. However, you can reference each DataFrame column by using all().

Code – Example 2

df_inv = pd.DataFrame({'Tops':     [36, 23, 19],
                       'Tanks':    [0, 0, -20],
                       'Pants':    [61, -33, 67],
                       'Sweats':   [88, 38, 13]})

result = df_inv.all()


dtype: bool

More Pandas DataFrame Methods

Feel free to learn more about the previous and next pandas DataFrame methods (alphabetically) here:

Also, check out the full cheat sheet overview of all Pandas DataFrame methods.