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