diff --git a/pandas/core/generic.py b/pandas/core/generic.py index 1404d225eea97..bb2810ba7857f 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -1372,16 +1372,36 @@ def __nonzero__(self): def bool(self): """ - Return the bool of a single element PandasObject. + Return the bool of a single element Series or DataFrame. - This must be a boolean scalar value, either True or False. Raise a - ValueError if the PandasObject does not have exactly 1 element, or that - element is not boolean + This must be a boolean scalar value, either True or False. It will raise a + ValueError if the Series or DataFrame does not have exactly 1 element, or that + element is not boolean (integer values 0 and 1 will also raise an exception). Returns ------- bool - Same single boolean value converted to bool type. + The value in the Series or DataFrame. + + See Also + -------- + Series.astype : Change the data type of a Series, including to boolean. + DataFrame.astype : Change the data type of a DataFrame, including to boolean. + numpy.bool_ : NumPy boolean data type, used by pandas for boolean values. + + Examples + -------- + The method will only work for single element objects with a boolean value: + + >>> pd.Series([True]).bool() + True + >>> pd.Series([False]).bool() + False + + >>> pd.DataFrame({'col': [True]}).bool() + True + >>> pd.DataFrame({'col': [False]}).bool() + False """ v = self.squeeze() if isinstance(v, (bool, np.bool_)):