首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >txt =“”.join(如果c不在string.punctuation中则为txt中的c=c)和TypeError:‘string.punctuation’对象不可迭代

txt =“”.join(如果c不在string.punctuation中则为txt中的c=c)和TypeError:‘string.punctuation’对象不可迭代
EN

Stack Overflow用户
提问于 2022-06-28 11:05:54
回答 1查看 59关注 0票数 0

有点奇怪。我有许多excel文件,每个文件中有超过50万个数据点。有些文件我可以删除停止和进行柠檬化,大多数文件都会出现以下错误

代码语言:javascript
复制
txt = "".join([c for c in txt if c not in string.punctuation])

TypeError:“浮点”对象不可迭代

感谢你的任何帮助

代码语言:javascript
复制
import nltk
wn = nltk.WordNetLemmatizer()
ps = nltk.PorterStemmer()
dir(wn)

import pandas as pd
import re
import string
from nltk.corpus import stopwords
pd.set_option ("display.max_colwidth", 200)
stop_word = set(stopwords.words("english"))
excel_path = (r"C:xxxx-BTC 21-30-4.xlsx")
data = pd.read_excel(excel_path)
data.columns = ["#","id", "date","Name","text_4"]


#clean text

def clean_text(txt) :
   txt = "".join([c for c in txt if c not in string.punctuation])
   tokens = re.split('\W+',txt)
   txt = [word for word in tokens if word not in stop_word]
   return txt

    data['text_5'] = data['text_4'].apply(lambda x: clean_text(x))
    #print(data.head)
#lemmatization

def lemmatization(tolken_txt):
    text = [wn.lemmatize(word) for word in tolken_txt]
    return text
data["text_6"] = data['text_5'].apply(lambda x: lemmatization(x))

print(data.head)
EN

回答 1

Stack Overflow用户

发布于 2022-06-28 13:40:07

你好,如果您确信列data['text_4']中没有浮点,则可能缺少不能交互的值。试着用"“来表示或填充。祝好运。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/72785326

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档