擅长:python、mysql、java
<p>与<code>groupby</code>一起使用<code>dropna</code>和<code>assign</code></p>
<p><a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.assign.html" rel="nofollow">docs to assign</a></p>
<pre><code>df1.dropna(subset=['Age', 'City']) \
.assign(Name=df1.groupby('Group').Name.apply(' '.join).values)
</code></pre>
<p><a href="https://i.stack.imgur.com/Vh8Go.png" rel="nofollow"><img src="https://i.stack.imgur.com/Vh8Go.png" alt="enter image description here"/></a></p>
<hr/>
<p>定时
每个请求</p>
<p><a href="https://i.stack.imgur.com/iYTBw.png" rel="nofollow"><img src="https://i.stack.imgur.com/iYTBw.png" alt="enter image description here"/></a></p>
<hr/>
<p><strong><em>更新</em></strong><br/>
使用<code>groupby</code>和<code>agg</code><br/>
我想到这一点,感觉更加满足</p>
<pre><code>df1.groupby('Group').agg(dict(Age='first', City='first', Name=' '.join))
</code></pre>
<p>得到准确的输出</p>
<pre><code>df1.groupby('Group').agg(dict(Age='first', City='first', Name=' '.join)) \
.reset_index().reindex_axis(df1.columns, 1)
</code></pre>