在datframe中,例如:
<div id="wrapper">
<div class="item-wrapper">
<child-stub></child-stub>
</div>
<div class="item-wrapper">
<child-stub></child-stub>
</div>
</div>
如何对以上数据框进行排序,以使子女最少的员工排在首位?
Employee list_of_children child
Jonathen ['John', 'Bob','Jennifer'] John
Jonathen ['John', 'Bob','Jennifer'] Bob
Jonathen ['John', 'Bob','Jennifer'] Jennifer
Emily ['Clark'] Clark
Hans ['Watson', 'Hans Jr'] Watson
Hans ['Watson', 'Hans Jr'] Watson
答案 0 :(得分:2)
获得argsort
后,我们可以使用len
df = df.iloc[df['list_of_children'].str.len().argsort()]