Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/google-cloud-platform/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 3.x ';浮动';对象在NLP中不可编辑_Python 3.x_Nlp - Fatal编程技术网

Python 3.x ';浮动';对象在NLP中不可编辑

Python 3.x ';浮动';对象在NLP中不可编辑,python-3.x,nlp,Python 3.x,Nlp,我正在从事一个自然语言处理项目。代码的目的是删除数据集中的所有标点符号。但是调用函数时报告了一个错误。原因是什么 def remove_punct(text): text_nopunct = ''.join([char for char in text if char not in string.punctuation]) return text_nopunct data['body_text_clean'] = data['body_text'].apply(lambda x

我正在从事一个自然语言处理项目。代码的目的是删除数据集中的所有标点符号。但是调用函数时报告了一个错误。原因是什么

def remove_punct(text):
    text_nopunct = ''.join([char for char in text if char not in string.punctuation])
    return text_nopunct

data['body_text_clean'] = data['body_text'].apply(lambda x: remove_punct(x))

我只是重申一下社区评论中的内容。评论中的答案是:

”.join([char-for-char-in-str(text),如果char不在string中。标点符号])
还可以尝试str(text)对非字符串变量进行类型转换。”
Earlee

运行时收到的具体错误消息是什么?我在测试中运行了你的代码,效果很好。你导入字符串了吗?
“”。加入([char for char in str(text),如果char不在string中。标点符号])
也尝试str(text)来输入非字符串变量。非常感谢,使用str(text)解决了我的问题,谢谢!