简体   繁体   English

获取“ AttributeError: 'float' object has no attribute 'lower' ”

[英]Getting “ AttributeError: 'float' object has no attribute 'lower' ”

I have a dataset of user comments and ratings.我有一个用户评论和评分数据集。 I am preprocessing this dataset but I get an error as below.我正在预处理此数据集,但出现如下错误。 How can I fix it?我该如何解决?

    def DataCleaning(metin):
     numbers = "0123456789"
     lower_case=metin.lower()
     punct_removed = [char for char in lower_case if char not in string.punctuation]
     punct_removed=[char for char in punct_removed if char not in numbers]
     punct_removed_join=''.join(punct_removed)
     punct_removed_join_clean = [word for word in punct_removed_join.split() if word not in 
     stopwords.words('english')]
     return punct_removed_join_clean


otel_verileri["reviews.text"] = otel_verileri["reviews.text"].apply(DataCleaning)
otel_verileri["reviews.text"].tolist()


OUTPUT:
AttributeError                            Traceback (most recent call last)
<ipython-input-56-a80b269d8bbe> in <module>()
      1 
----> 2 otel_verileri["reviews.text"] = otel_verileri["reviews.text"].apply(DataCleaning)
      3 otel_verileri["reviews.text"].tolist()

1 frames
pandas/_libs/lib.pyx in pandas._libs.lib.map_infer()

<ipython-input-48-748ef67e84ac> in DataCleaning(metin)
      1 def DataCleaning(metin):
      2  numbers = "0123456789"
----> 3  lower_case=metin.lower()
      4  punct_removed = [char for char in lower_case if char not in string.punctuation]
      5  punct_removed=[char for char in punct_removed if char not in numbers]

AttributeError: 'float' object has no attribute 'lower'

I am guessing that you use the pandas library.我猜你使用的是 pandas 库。 I don't know if you are reading an excel file but I'll assume it.我不知道您是否正在阅读 excel 文件,但我会假设它。

Pandas seems to like inferring types on its own. Pandas 似乎喜欢自己推断类型。 you can suppress that and demand a specific column be only str using this:你可以抑制它并要求一个特定的列只是str使用这个:

otel_verileri = pd.read_excel(file_name, converters={'reviews.text' : str})

( source: another answer on SO ) 来源:关于 SO 的另一个答案

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 AttributeError: 'list' object 没有属性 'lower' 与 CountVectorizer - AttributeError: 'list' object has no attribute 'lower' with CountVectorizer AttributeError: 'list' object 在训练时没有属性 'lower' - AttributeError: 'list' object has no attribute 'lower' at the time of training python 2.7-CountVectorizer错误:AttributeError:&#39;file&#39;对象没有属性&#39;lower&#39; - python 2.7 - CountVectorizer error :AttributeError: 'file' object has no attribute 'lower' AttributeError 抛出表示列表 object 没有较低的属性 - AttributeError throwing up which says list object has no attribute lower AttributeError:&#39;list&#39;对象没有来自Tfidf_vect.fit的属性&#39;lower&#39; - AttributeError: 'list' object has no attribute 'lower' from Tfidf_vect.fit AttributeError: 'list' object 在词频逆文档频率中没有属性 'lower' - AttributeError: 'list' object has no attribute 'lower' in term frequency inverse document frequency AttributeError: 'list' object 在尝试拟合二维数组时没有属性 'lower' 错误 - AttributeError: 'list' object has no attribute 'lower' error when trying to fit a 2d array AttributeError: 'NoneType' object has no attribute 'lower' in Python。如何在标记文本内容之前进行预处理? - AttributeError: 'NoneType' object has no attribute 'lower' in Python. How to preprocess before tokenizing the text content? Python:列表对象没有属性 &#39;lower&#39; - 但语料库已经是小写了 - Python: list object has no attribute 'lower' - but corpus is already in lower case AttributeError:“ InputLayer”对象没有属性“ W” - AttributeError:'InputLayer' object has no attribute 'W'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM