Skip to content

Commit 8ba9c62

Browse files
DOC: Improve docstring of Series/DataFrame.bool (#34229)
1 parent 7d0ee96 commit 8ba9c62

File tree

1 file changed

+25
-5
lines changed

1 file changed

+25
-5
lines changed

pandas/core/generic.py

+25-5
Original file line numberDiff line numberDiff line change
@@ -1372,16 +1372,36 @@ def __nonzero__(self):
13721372

13731373
def bool(self):
13741374
"""
1375-
Return the bool of a single element PandasObject.
1375+
Return the bool of a single element Series or DataFrame.
13761376
1377-
This must be a boolean scalar value, either True or False. Raise a
1378-
ValueError if the PandasObject does not have exactly 1 element, or that
1379-
element is not boolean
1377+
This must be a boolean scalar value, either True or False. It will raise a
1378+
ValueError if the Series or DataFrame does not have exactly 1 element, or that
1379+
element is not boolean (integer values 0 and 1 will also raise an exception).
13801380
13811381
Returns
13821382
-------
13831383
bool
1384-
Same single boolean value converted to bool type.
1384+
The value in the Series or DataFrame.
1385+
1386+
See Also
1387+
--------
1388+
Series.astype : Change the data type of a Series, including to boolean.
1389+
DataFrame.astype : Change the data type of a DataFrame, including to boolean.
1390+
numpy.bool_ : NumPy boolean data type, used by pandas for boolean values.
1391+
1392+
Examples
1393+
--------
1394+
The method will only work for single element objects with a boolean value:
1395+
1396+
>>> pd.Series([True]).bool()
1397+
True
1398+
>>> pd.Series([False]).bool()
1399+
False
1400+
1401+
>>> pd.DataFrame({'col': [True]}).bool()
1402+
True
1403+
>>> pd.DataFrame({'col': [False]}).bool()
1404+
False
13851405
"""
13861406
v = self.squeeze()
13871407
if isinstance(v, (bool, np.bool_)):

0 commit comments

Comments
 (0)