擅长:python、mysql、java
<p>您可以将<code>groupby</code>与<code>apply(pd.Series)</code>一起使用</p>
<pre><code>df.groupby(['ID','col']).col2.apply(list).apply(pd.Series).add_prefix('col').reset_index()
Out[404]:
ID col col0 col1
0 1 A 50.0 52.0
1 1 B 45.0 NaN
2 1 C 18.0 NaN
</code></pre>