【发布时间】:2022-06-13 20:28:04
【问题描述】:
【问题讨论】:
-
你试过了吗?
-
另外,请将数据/代码发布为text and not as images。
-
我们都时不时地想要一些东西——但是那些试图让它成功的人,即使他们需要一些来自 SO 的帮助。 how to ask
【问题讨论】:
一种方法是计算真实出现次数,然后根据计数删除行,如下所示:df['count'] = df[['1', '2']].sum(axis=1)
然后像这样下降:df3 = df[df['count'] > 2]
希望我没有解决你的作业xD
【讨论】:
import pandas as pd
df = {
"0": [True, True, True, True, True],
"1": [True, False, False, False, True],
"2": [True, False, False, False, False],
"3": [True, False, False, False, False],
"4": [True, False, False, False, False]
}
df = pd.DataFrame(df)
print(df)
for i in range(df.shape[0]):
criteria_value = 2
count = 0
for column_name in df.columns:
if df.loc[i][column_name]:
count += 1
if count == criteria_value:
df.drop(index=i, inplace=True)
print(df)
【讨论】: