擅长:python、mysql、java
<p>可以使用<code>merge</code>,然后使用条件。你知道吗</p>
<pre><code>n_hood_cost_count= df.groupby(['Land Code','Style'])['Assessment_per_living'].mean().reset_index()
df_new = df.merge(n_hood_cost_count,on=['Land Code','Style'],how='outer')
df_new = df[df_new['Assessment_per_living_x']>df_new['Assessment_per_living_y']]
</code></pre>
<p>输出</p>
<pre>
Style Land Code Assessment_per_living
2 Cape 1010 109.222000
4 Colonial 1010 77.270968
5 Cape 1011 80.856481
8 Colonial 1011 67.856000
9 Colonial 1011 79.564000
11 Ranch 1011 57.810434
13 Colonial 1012 107.820248
14 Colonial 1012 84.827050
17 Ranch 1012 109.641711
</pre>