数据帧中字符串的长度

时间:2018-09-19 16:04:41

标签: string python-3.x dataframe

我正在尝试创建一个新列,其长度由某人发表:

message['TextLength'] = message['MessageContent'].apply(len)

令人讨厌的是,有趣的是,这是我已经完成的很多任务。有时有效,有时无效。无效时引发的错误:

TypeError: object of type 'float' has no len()

错误很明显;您不能在浮点数上使用len()。但是,我的数据框包含文本消息,字符串,所以有点困惑。

message dataframe:

Label                 MessageContent

ham   Go until jurong point, crazy.. 

ham   Ok lar... Joking wif u oni... 

spam  Free entry in 2 a wkly comp to win FA Cup fina... 

ham   U dun say so early hor... U c already then say... 

ham   Nah I don't think he goes to usf, he lives aro... 

如果有人有办法解决这个问题,或者知道为什么会出现此错误,那就太好了

0 个答案:

没有答案