簡體   English   中英

AttributeError: 'list' 對象沒有屬性 'replace' "fasttext"

[英]AttributeError: 'list' object has no attribute 'replace' "fasttext"

目前我正在使用 fastText 開發堆棧溢出標簽預測器。

我想將我的標簽設為__label__XX__label__YY ,其中XXYY是數據幀特定行的標簽。

tags= df['Tags']

我的tags列表是:

0                 [php]
1             [firefox]
2                   [r]
3                  [c#]
4            [php, api]
...      
179995         [delphi]
179996              [c]
179997        [android]
179998    [java, email]
179999     [linux, php]

Name: Tags, Length: 135552, dtype: object

運行線路時

tags=[s.replace(',' , '__label__') for s in tags]

我收到一個錯誤:

AttributeError  Traceback (most recent call last)
<ipython-input-139-dd4edc84bcad> in <module>
----> 1 tags=[s.replace(' ','__label__') for s in tags]
<ipython-input-139-dd4edc84bcad> in <listcomp>(.0)
----> 1 tags=[s.replace(' ','__label__') for s in tags]

AttributeError: 'list' object has no attribute 'replace'

我還在這里發布了我的筆記本屏幕截圖

#tags=[s.replace(' ','__label__') for s in tags]
tags =['__label__'.join(s) for s in tags]

試試這個,你應該得到想要的結果

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM