擅长:python、mysql、java
<p>您无需<code>pd.concat</code>即可完成此操作。使用<code>__name__</code>命名自定义函数,并将它们作为列表传递。你知道吗</p>
<pre><code>def simple_mean(x):
return x.mean()
def custom_mean(x):
return max(x.mean(), 1-x.mean())
simple_mean.__name__ = 'Avg_Response'
custom_mean.__name__ = 'Agreement'
df.groupby('Post')['Response'].agg([simple_mean, custom_mean])
Avg_Response Agreement
Post
text1 0.333333 0.666667
text2 0.666667 0.666667
</code></pre>