我的數據幀或浮點數中都沒有空值。但是,錯誤仍然存在。以下是有關我的數據的一些信息:關于空值(據我所知,numpy.nans 在 pandas 中被編碼為浮點數):?關于數據類型:當我這樣做時:from tensorflow.keras.preprocessing.text import Tokenizertitle_tokeniser = Tokenizer(num_words=10)title_tokeniser.fit_on_texts(train_set.loc[:,'title'] + test_set.loc[:,'title'])這是錯誤:---------------------------------------------------------------------------AttributeError? ? ? ? ? ? ? ? ? ? ? ? ? ? Traceback (most recent call last)<ipython-input-38-26b704f1c0a1> in <module>()? ? ? 1 title_tokeniser = Tokenizer(num_words=10)----> 2 title_tokeniser.fit_on_texts(train_set.loc[:,'title'] + test_set.loc[:,'title'])? ? ? 3?? ? ? 4 # unique tokens found in titles are:? ? ? 5 title_token_index = title_tokeniser.word_index1 frames/usr/local/lib/python3.6/dist-packages/keras_preprocessing/text.py in fit_on_texts(self, texts)? ? 223? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?self.filters,? ? 224? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?self.lower,--> 225? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?self.split)? ? 226? ? ? ? ? ? ?for w in seq:? ? 227? ? ? ? ? ? ? ? ?if w in self.word_counts:/usr/local/lib/python3.6/dist-packages/keras_preprocessing/text.py in text_to_word_sequence(text, filters, lower, split)? ? ?41? ? ?"""? ? ?42? ? ?if lower:---> 43? ? ? ? ?text = text.lower()? ? ?44?? ? ?45? ? ?if sys.version_info < (3,):AttributeError: 'float' object has no attribute 'lower'
1 回答

紅糖糍粑
TA貢獻1815條經驗 獲得超6個贊
嘗試這個
texts = pd.concat([train_set['title'] , test_set['title']],axis=0).astype("str")
from tensorflow.keras.preprocessing.text import Tokenize
title_tokeniser = Tokenizer(num_words=10)
title_tokeniser.fit_on_texts(texts)
添加回答
舉報
0/150
提交
取消