pandas.core.groupby.DataFrameGroupBy.all#
- DataFrameGroupBy.all(skipna=True)[源代码]#
如果组中的所有值都为真,则返回 True,否则返回 False。
- Parameters:
- <strong>skipna</strong>bool, default True
在布尔测试期间忽略 nan 值的标志。
- Returns:
- Series 或 DataFrame
布尔值的 DataFrame 或 Series,其中如果其各自组中的所有元素都为 True,则值为 True,否则为 False。
参见
Series.groupby将函数 groupby 应用于 Series。
DataFrame.groupby将函数 groupby 应用于 DataFrame 的每一行或每一列。
Examples
对于 SeriesGroupBy:
>>> lst = ['a', 'a', 'b'] >>> ser = pd.Series([1, 2, 0], index=lst) >>> ser a 1 a 2 b 0 dtype: int64 >>> ser.groupby(level=0).all() a True b False dtype: bool
对于 DataFrameGroupBy:
>>> data = [[1, 0, 3], [1, 5, 6], [7, 8, 9]] >>> df = pd.DataFrame(data, columns=["a", "b", "c"], ... index=["ostrich", "penguin", "parrot"]) >>> df a b c ostrich 1 0 3 penguin 1 5 6 parrot 7 8 9 >>> df.groupby(by=["a"]).all() b c a 1 False True 7 True True