擅长:python、mysql、java
<p>我能想到的没有循环的pandas方法的唯一方法是在重置索引并与<code>df.all(1)</code>进行比较之后的交叉连接</p>
<pre><code>cols = ['och1','och2','och3','cch1']
u = df2.reset_index().assign(k=1).merge(
dffinal.reset_index().assign(k=1),on='k',suffixes=('','_y'))
#for new Version of pandas there is a how='cross' included now
dffinal['NewLCH'] = (u[u[cols].gt(u[[f"{i}_y" for i in cols]].to_numpy()).all(1)]
.groupby("index_y")['och'].mean())
</code></pre>
<hr/>
<pre><code>print(dffinal)
date id och och1 och2 och3 cch1 LCH L# NewLCH
0 3/27/2020 1 -2.1 3 3 1 5 NaN NaN 0.900000
1 4/9/2020 2 2.0 1 2 1 3 NaN NaN 1.166667
</code></pre>