我想根据字符串的长度(最长的第一个)对数据框中的列表进行排序
brand serie
&tradition [&tradition flowerpot, &tradition spinning pen, &tradition test]
Dove [dove deeply nourishing, dove men+care]
Adidas [adidas ace, adidas gel]
Vasaline [vaseline advanced repair, vaseline men]
Boska [boska dutch, boska test2, boska testing]
我希望结果看起来像这样:
brand serie
..... ......
Boska [boska testing, boska dutch, boska test2]
提前感谢您的帮助!
答案 0 :(得分:1)
您可以将pd.Series.apply
与sorted
:
def sorter(x):
return sorted(x, key=len, reverse=True)
df['serie'] = df['serie'].apply(sorter)