擅长:python、mysql、java
<p>下面是一种使用<code>groupby</code>+<code>transform</code>的自定义函数的方法:</p>
<pre><code>def stringer(x):
return '('+', '.join(map(str, x))+')'
df['Name'] += df.groupby('Name')['Batch'].transform(stringer)
print(df)
Batch Name
0 1 Jon(1, 4)
1 2 Adam(2)
2 3 Voges(3)
3 4 Jon(1, 4)
</code></pre>
<hr/>
<p><strong>更新空行核算</strong></p>
<p>在这种情况下,可以使用<code>numpy.where</code>:</p>
^{pr2}$