pandas:IndexingError:作为索引器提供的不可对齐的布尔系列

pandas:IndexingError:作为索引器提供的不可对齐的布尔系列,第1张

pandas:IndexingError:作为索引器提供的不可对齐的布尔系列

您需要

loc
,因为按列过滤

print (df.notnull().any(axis = 0))a     Trueb     Truec     Trued    Falsedtype: booldf = df.loc[:, df.notnull().any(axis = 0)]print (df)     a    b    c0  1.0  4.0  NaN1  2.0  NaN  8.02  NaN  6.0  9.03  NaN  NaN  NaN

或过滤列,然后按

[]

print (df.columns[df.notnull().any(axis = 0)])Index(['a', 'b', 'c'], dtype='object')df = df[df.columns[df.notnull().any(axis = 0)]]print (df)     a    b    c0  1.0  4.0  NaN1  2.0  NaN  8.02  NaN  6.0  9.03  NaN  NaN  NaN

dropna
使用参数
how='all'
删除
NaN
仅由s填充的所有列:

print (df.dropna(axis=1, how='all'))     a    b    c0  1.0  4.0  NaN1  2.0  NaN  8.02  NaN  6.0  9.03  NaN  NaN  NaN


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/zaji/5649992.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-16
下一篇 2022-12-16

发表评论

登录后才能评论

评论列表(0条)

保存