擅长:python、mysql、java
<p>您可以使用<a href="https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.apply.html" rel="nofollow noreferrer">pandas' apply function</a>并定义自己的函数来检查您的条件,如下所示:</p>
<pre><code># columns you want to check. Note they have to be in the right order!!
columns = ["A", "B", "C", "D"]
# Custom function you apply over df, takes a row as input
def zeros_condition(row):
# loop over the columns.
for n in range(len(columns)-1):
# return true if 0s in two adjacent columns, else false
if row[columns[n]] == row[columns[n+1]] == 0:
return True
return False
result = df.apply(zeros_condition, axis=1)
</code></pre>
<p>结果是:</p>
^{pr2}$