tweepyライブラリを使用してツイートテキストのリストを取得すると、200個のツイートの単語をストップワードのリストと比較し、つぶやきのテキストリストの単語は、検索されたつぶやきの中で最も表示される単語が何であるかを言うことができます。'utf-8'でエンコードされた文字列のリストを通常の文字列に変換する
私がtweet.textsを取得するときは、それを得るためにエンコードしなければならないので、b'wordのリストを取得する必要があります。これは、通常の文字列であるストップワードのリストとは比較できません。
def get_tweetwords():
print("Ingrese el hashtag a buscar, no olvide escribir el numeral (#)(Ctrl+3)")
hashtag=str(input())
while (hashtag[0])!="#":
print("No olvide escribir el numeral. Vuelva a escribir el hashtag:")
hashtag=str(input())
busqueda=tweepy.Cursor(api.search,q=hashtag).items(10)
twlist=[]
listadepalabras=[]
for tweets in busqueda:
twlist.append(tweets.text.encode('utf-8'))
for i in twlist:
x=i.split()
for j in x:
listadepalabras.append(j)
return(listadepalabras)
私はstopwords
リストと比較し、そのストップワードを除去するために、文字列リストにlistadepalabras
リストをデコードする必要があります。
def get_stopwords():
listastopwords=[item for item in open("stopwords.txt").readlines()]
for item in listastopwords:
if "\n" in listastopwords:
listastopwords[listastopwords.index(item)]=item.replace("\n","")
return(listastopwords)
def sacar_stopwords():
listadepalabras=get_tweetwords()
listastopwords=get_stopwords()
for i in listadepalabras:
for j in listastopwords:
if i==j:
listadepalabras.remove(j)
return(listadepalabras)
私のテキストリストがb'word'
形式での単語が含まれていますし、私のストップワードリストがちょうど'word'
def repeticiones_palabra():
listadepalabras=sacar_stopwords()
diccionario=collections.Counter(listadepalabras)
diccionario=dict(diccionario.most_common(10))
print ("-LAS 10 PALABRAS MAS UTILIZADAS SON-")
print(diccionario)
である。これは私の私のリストにある10個の最も使用される単語を取得する必要がありますし、それが働いているので、これが動作しません私はストップワードがリストから削除されていないと言うことができるので、私はほとんどのストップワードとハッシュタグを探しています。
repeticiones_palabra()
私は私のpythonに初心者イム、自分自身を明らかにしたと同様に、スタックオーバーフローしたいと考えています。前もって感謝します。
lst = [b'abc', b'def']
# >>> [b'abc', b'def']
lst2 = [s.decode("utf-8") for s in lst]
# >>> ['abc', 'def']
EDIT: 私がいることがわかり
Bはバイト文字列ではなく、UTF-8文字列です。 "abcde" .decode( "utf-8") –