<p>由于您无法确定条件只返回一行或多行,因此最好创建一系列元组,并根据条件返回的行数重复该元组:</p>
<pre><code>condition = df['points'] == 50
df.loc[condition, 'auditor'] = pd.Series([(1, 2)]).repeat(condition.sum()).values
</code></pre>
<hr/>
<pre><code>print(df)
points time year month points_h1 auditor
0 50.0 5:00 2010.0 NaN NaN (1, 2)
1 25.0 6:00 NaN february NaN None
2 90.0 9:00 NaN january NaN None
3 NaN NaN NaN june 20.0 None
</code></pre>
<hr/>
<P>为了了解我的意思,让我们考虑第二行也有{{CD1>}为50:</p>
<pre><code>d = [{'points': 50, 'time': '5:00', 'year': 2010},
{'points': 50, 'time': '6:00', 'month': "february"},
{'points': 90, 'time': '9:00', 'month': 'january'},
{'points_h1': 20, 'month': 'june'}]
df = pd.DataFrame(d)
df['auditor'] = None
print(df,'\n\n')
condition = df['points'] == 50
df.loc[condition, 'auditor'] = pd.Series([(1, 2)]).repeat(condition.sum()).values
print(df)
</code></pre>
<hr/>
<pre><code> points time year month points_h1 auditor
0 50.0 5:00 2010.0 NaN NaN None
1 50.0 6:00 NaN february NaN None
2 90.0 9:00 NaN january NaN None
3 NaN NaN NaN june 20.0 None
points time year month points_h1 auditor
0 50.0 5:00 2010.0 NaN NaN (1, 2)
1 50.0 6:00 NaN february NaN (1, 2)
2 90.0 9:00 NaN january NaN None
3 NaN NaN NaN june 20.0 None
</code></pre>