我正在尝试删除df
cols = df.columns[df.isna().any()].tolist()
df = df.dropna([cols], axis = 1)
但是我收到了错误
TypeError:dropna()为参数'轴'
获取了多个值
我怎么能把列表中的列表删除?
答案 0 :(得分:1)
我认为需要boolean indexing
与 data = [{ col1: 'one', col2: 'two' }, { col1: 'uno', col2: 'duo' }];
emptyObject = { col1: 'ww', col2: 'gg' };
index = 3;
columns = ['col1', 'col2'];
addRow() {
this.data.push(Object.assign({}, this.emptyObject));
}
addColumn() {
const c = 'col' + this.index++;
this.columns.push(c);
this.emptyObject[c] = 'edit me';
this.data.forEach(row => row[c] = 'edit me');
}
:
loc
对于您的解决方案,需要df1 = df.loc[:, df.notna().all()]
#alternative with iverting mask by ~
#df1 = df.loc[:, ~df.isna().any()]
#alternative 1
#df1 = df.dropna(axis=1)
并使用省略列表drop
来删除列:
[]