pandas - select 列子集的布尔过滤为真的行

pandas - select rows where the boolean filtering of a subset of columns are true

我有一个数据框 'df',我想从中 select 3 个特定列不为空的子集。

到目前为止,我已经尝试应用 bool 过滤

mask_df = df[['Empty', 'Peak', 'Full']].notnull()

这给了我以下结果

    Empty   Peak    Full
0   True    False   False
1   False   False   False
2   True    True    True
3   False   False   False
4   False   False   False
... ... ... ...
2775244 True    True    True
2775245 True    True    True
2775246 False   False   False
2775247 False   False   False
2775248 False   False   False

现在我只想 select 那些 3 列的掩码为 True 的行(即,这 3 列具有空值的行)。如果我用这个掩码过滤原始数据帧 'df' 我得到充满空值的原始数据帧,除了那些 mask_df 是“真”的数据帧。

我可能可以通过按行应用 lambda 函数来做到这一点,但如果有更简单的方法来做到这一点,我宁愿避免这种计算。

提前致谢!

使用pandas.DataFrame.all:

df[mask_df.all(axis = 1)]