首页 > 解决方案 > df.apply(lambda: x.lower()): 'function' 对象没有属性 'lower'

问题描述

我在 Jupyter 中编写了这段代码,但收到一条错误消息:

tokenizer = RegexpTokenizer (r'\w+')

career_df['How could the conversation have been more useful?']= career_df['How could the conversation have been more useful?'].apply(lambda x:tokenizer.tokenize(x.lower()))

错误是

AttributeError:'function'对象没有属性'lower'

标签: pythondataframestringtokenizer

解决方案


lambda 表达式中的“x”在应该是字符串时充当函数。尝试 :

  career_df['How could the conversation have been more useful?']= career_df.apply(lambda x:tokenizer.tokenize(x['How could the conversation have been more useful?'].lower()))

推荐阅读