我需要将此for循环转换为列表理解。此for循环遍历数据框以查找列'TL'
的条目包含“J”和列'Ink' = 0
的每一行并删除整行:
for r in df.T:
if 'J' in df.loc[r,'TL'] and df.loc[r,'Ink'] == 0:
df.drop(r)
else:
continue
我试过这个
df_clean = [
df.drop(r) for r in df.T if 'J' in df.loc[r,'TL'] and df.loc[r,'Ink'] == 0
]
我收到错误说明
ValueError:DataFrame的真值是不明确的。使用a.empty,a.bool(),a.item(),a.any()或a.all()。
答案 0 :(得分:2)
尝试:
df[~(df.TL.str.contains('J') & df.Ink.eq(0))]