File tree 1 file changed +25
-5
lines changed
1 file changed +25
-5
lines changed Original file line number Diff line number Diff line change @@ -1372,16 +1372,36 @@ def __nonzero__(self):
1372
1372
1373
1373
def bool (self ):
1374
1374
"""
1375
- Return the bool of a single element PandasObject .
1375
+ Return the bool of a single element Series or DataFrame .
1376
1376
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).
1380
1380
1381
1381
Returns
1382
1382
-------
1383
1383
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
1385
1405
"""
1386
1406
v = self .squeeze ()
1387
1407
if isinstance (v , (bool , np .bool_ )):
You can’t perform that action at this time.
0 commit comments