检查df中是否存在多列

dai*_*yue 6 python dataframe python-3.x pandas

我想知道如何正确检查,如果在存在多列df,说如果我想测试,如果两列A,并B在存在df

if `A` in df and `B` in df:
    # some code
Run Code Online (Sandbox Code Playgroud)

有没有更好的方法来做这个检查?用 测试过['A', 'B'] in df,但失败了。

更新

 pd.Series(['A', 'B']).isin(df.columns).all()
Run Code Online (Sandbox Code Playgroud)

会做的工作。