我要在df ['Stem']列中查找每行字符数最少的单词,并将该值放入df ['lab']
电流输出
group stem lab
----------------- --------- --------------------- -------------
notif notify, notified nan
face-to-fac face-to-face nan
propo proposed nan
lift lifted nan
govern governed, governing, government, governance nan
constitut constitute, constitutional nan
exp expedient nan
prev preventing, prevent nan
tre treat, treatment nan
work working, works nan
预期产量
group stem lab
----------------- --------- --------------------- -------------
notif notify, notified notify
face-to-fac face-to-face face-to-face
propo proposed proposed
lift lifted lifted
govern governed, governing, government, governance governed
constitut constitute, constitutional constitute
exp expedient expedient
prev preventing, prevent prevent
tre treat, treatment treat
work working, works works
尝试
df['lab'] = df.stem.str.split(',').apply(lambda x: min(x, key=len))
但它给予了
TypeError: 'float' object is not iterable
答案 0 :(得分:4)