1
1
.. currentmodule :: pandas
2
2
3
+ .. ipython :: python
4
+ :suppress:
5
+
6
+ import pandas as pd
7
+ import numpy as np
8
+
3
9
.. _boolean :
4
10
5
11
**************************
@@ -13,48 +19,33 @@ Nullable Boolean Data Type
13
19
Kleene Logic
14
20
------------
15
21
16
- :class: `arrays.BooleanArray ` implements Kleene logic (sometime called three-value logic) for
22
+ :class: `arrays.BooleanArray ` implements Kleene logic (sometimes called three-value logic) for
17
23
logical operations like ``& `` (and), ``| `` (or) and ``^ `` (exclusive-or).
18
24
19
25
Here's a table for ``and ``.
20
26
21
- ========== =========== ============
22
- left value right value output value
23
- ========== =========== ============
24
- True True True
25
- True False False
26
- True NA NA
27
- False False False
28
- False NA False
29
- NA NA NA
30
- ========== =========== ============
31
-
32
-
33
- And for ``or ``
34
-
35
- ========== =========== ============
36
- left value right value output value
37
- ========== =========== ============
38
- True True True
39
- True False True
40
- True NA True
41
- False False False
42
- False NA NA
43
- NA NA NA
44
- ========== =========== ============
45
-
46
- And for ``xor ``
47
-
48
- ========== =========== ============
49
- left value right value output value
50
- ========== =========== ============
51
- True True False
52
- True False True
53
- True NA NA
54
- False False False
55
- False NA NA
56
- NA NA NA
57
- ========== =========== ============
27
+ ================= =========
28
+ Expression Result
29
+ ================= =========
30
+ ``True & True `` ``True ``
31
+ ``True & False `` ``False ``
32
+ ``True & NA `` ``NA ``
33
+ ``False & False `` ``False ``
34
+ ``False & NA `` ``False ``
35
+ ``NA & NA `` ``NA ``
36
+ ``True | True `` ``True ``
37
+ ``True | False `` ``True ``
38
+ ``True | NA `` ``True ``
39
+ ``False | False `` ``False ``
40
+ ``False | NA `` ``NA ``
41
+ ``NA | NA `` ``NA ``
42
+ ``True ^ True `` ``False ``
43
+ ``True ^ False `` ``True ``
44
+ ``True ^ NA `` ``NA ``
45
+ ``False ^ False `` ``False ``
46
+ ``False ^ NA `` ``NA ``
47
+ ``NA ^ NA `` ``NA ``
48
+ ================= =========
58
49
59
50
When an ``NA `` is present in an operation, the output value is ``NA `` only if
60
51
the result cannot be determined soley based on the other input. For example,
@@ -79,5 +70,7 @@ In ``or``
79
70
80
71
In ``and ``
81
72
73
+ .. ipython :: python
74
+
82
75
pd.Series([True , False , np.nan], dtype = " object" ) & True
83
76
pd.Series([True , False , np.nan], dtype = " boolean" ) & True
0 commit comments