Skip to main content

__ Back to top

__ ` Ctrl ` \+ ` K `

[ ![pandas 2.2.1 documentation - Home](../_static/pandas.svg) ](../index.html)

Site Navigation

  * [ Getting started ](../getting_started/index.html)
  * [ User Guide ](index.html)
  * [ API reference ](../reference/index.html)
  * [ Development ](../development/index.html)
  * [ Release notes ](../whatsnew/index.html)

  * [ __ GitHub  ](https://github.com/pandas-dev/pandas "GitHub")
  * [ __ Twitter  ](https://twitter.com/pandas_dev "Twitter")
  * [ __ Mastodon  ](https://fosstodon.org/@pandas_dev "Mastodon")

Site Navigation

  * [ Getting started ](../getting_started/index.html)
  * [ User Guide ](index.html)
  * [ API reference ](../reference/index.html)
  * [ Development ](../development/index.html)
  * [ Release notes ](../whatsnew/index.html)

  * [ __ GitHub  ](https://github.com/pandas-dev/pandas "GitHub")
  * [ __ Twitter  ](https://twitter.com/pandas_dev "Twitter")
  * [ __ Mastodon  ](https://fosstodon.org/@pandas_dev "Mastodon")

  * [ 10 minutes to pandas ](10min.html)
  * [ Intro to data structures ](dsintro.html)
  * [ Essential basic functionality ](basics.html)
  * [ IO tools (text, CSV, HDF5, â¦) ](io.html)
  * [ PyArrow Functionality ](pyarrow.html)
  * [ Indexing and selecting data ](indexing.html)
  * [ MultiIndex / advanced indexing ](advanced.html)
  * [ Copy-on-Write (CoW) ](copy_on_write.html)
  * [ Merge, join, concatenate and compare ](merging.html)
  * [ Reshaping and pivot tables ](reshaping.html)
  * [ Working with text data ](text.html)
  * [ Working with missing data ](missing_data.html)
  * [ Duplicate Labels ](duplicates.html)
  * [ Categorical data ](categorical.html)
  * [ Nullable integer data type ](integer_na.html)
  * Nullable Boolean data type 
  * [ Chart visualization ](visualization.html)
  * [ Table Visualization ](style.html)
  * [ Group by: split-apply-combine ](groupby.html)
  * [ Windowing operations ](window.html)
  * [ Time series / date functionality ](timeseries.html)
  * [ Time deltas ](timedeltas.html)
  * [ Options and settings ](options.html)
  * [ Enhancing performance ](enhancingperf.html)
  * [ Scaling to large datasets ](scale.html)
  * [ Sparse data structures ](sparse.html)
  * [ Frequently Asked Questions (FAQ) ](gotchas.html)
  * [ Cookbook ](cookbook.html)

  * [ __ ](../index.html)
  * [ User Guide ](index.html)
  * Nullable... 

#  Nullable Boolean data type  #

Note

BooleanArray is currently experimental. Its API or implementation may change
without warning.

##  Indexing with NA values  #

pandas allows indexing with ` NA  ` values in a boolean array, which are
treated as ` False  ` .

    
    
    In [1]: s = pd.Series([1, 2, 3])
    
    In [2]: mask = pd.array([True, False, pd.NA], dtype="boolean")
    
    In [3]: s[mask]
    Out[3]: 
    0    1
    dtype: int64
    

If you would prefer to keep the ` NA  ` values you can manually fill them with
` fillna(True)  ` .

    
    
    In [4]: s[mask.fillna(True)]
    Out[4]: 
    0    1
    2    3
    dtype: int64
    

##  Kleene logical operations  #

[ ` arrays.BooleanArray  ` ](../reference/api/pandas.arrays.BooleanArray.html#pandas.arrays.BooleanArray "pandas.arrays.BooleanArray") implements [ Kleene Logic ](https://en.wikipedia.org/wiki/Three-valued_logic#Kleene_and_Priest_logics) (sometimes called three-value logic) for logical operations like ` & ` (and), ` |  ` (or) and ` ^  ` (exclusive-or). 

This table demonstrates the results for every combination. These operations
are symmetrical, so flipping the left- and right-hand side makes no difference
in the result.

Expression  |  Result   
---|---  
` True  & True  ` |  ` True  `  
` True  & False  ` |  ` False  `  
` True  & NA  ` |  ` NA  `  
` False  & False  ` |  ` False  `  
` False  & NA  ` |  ` False  `  
` NA  & NA  ` |  ` NA  `  
` True  |  True  ` |  ` True  `  
` True  |  False  ` |  ` True  `  
` True  |  NA  ` |  ` True  `  
` False  |  False  ` |  ` False  `  
` False  |  N