ウェブページから単語の頻度を数えた後、ストップワードを削除しようとしていました。以下は、私のコードです:点1のpython - ウェブページから繰り返し単語を抽出し、ストップワードを削除する
import requests
from bs4 import BeautifulSoup
from collections import Counter
import pandas as pd
from nltk.corpus import stopwords
stop = stopwords.words('english')
Website1 = requests.get("http://www.nerdwallet.com/the-best-credit-cards")
soup = BeautifulSoup(Website1.content)
texts = soup.findAll(text=True)
a = Counter([x.lower() for y in texts for x in y.split()])
b = (a.most_common())
makeaframe = pd.DataFrame(b)
makeaframe.columns = ['Words', 'Frequency']
print (makeaframe) --------1
makeaframe['Words']=makeaframe['Words'].apply(lambda x: [item for item in x if item not in stop])
print(makeaframe) ----------2
私は私のためokですどのような出力が得られます。今
Words Frequency
0 the 412
1 on 386
2 and 368
3 for 364
4 credit 340
5 a 335
6 to 295
7 card 269
ポイント1の後、私はストップワードを削除しようと、私は次のことを期待していました。
Words Frequency
4 credit 340
7 card 269
しかし、代わりに私が取得:
Words Frequency
0 [h, e] 412
1 [n] 386
2 [n] 368
3 [f, r] 364
4 [c, r, e] 340
5 [] 335
6 [] 295
7 [c, r] 269
私はこの問題を介して取得するためにインターネットを閲覧けど見つけるcouldntの私はラムダ関数は、文字で手紙を読むと、ストップワードをremvoingたと思いますし、私は、次のような機能を試してみました介して取得couldntの..
#print makeaframe.ix[:,'Words'].apply(lambda Words: [for Words not in stop])
#print makeaframe.ix[:,'Words'].apply(lambda Words: [item for item in Words if item not in stop])
#makeaframe['Words']=[word for word in makeaframe['Words'] if word not in stop]
解決策は..あなたは、単にとして、リストを作成することができるはず