0
txtファイルのテキストからバイグラムの頻度を見つけようとしています。これまでのところ、それは動作しますが、それは数字をカウントし、symbols.Hereは私が持っているコードです:!。?Python-ビッグラム周波数の数字と記号を無視する
import nltk
from nltk.collocations import *
import prettytable
file = open('tweets.txt').read()
tokens = nltk.word_tokenize(file)
pt = prettytable.PrettyTable(['Words', 'Counts'])
pt.align['Words'] = 'l'
pt.align['Counts'] = 'r'
bgs = nltk.bigrams(tokens)
fdist = nltk.FreqDist(bgs)
for row in fdist.most_common(100):
pt.add_row(row)
print pt
Below is the code output:
+------------------------------------+--------+
| Words | Counts |
+------------------------------------+--------+
| ('https', ':') | 1615 |
| ('!', '#') | 445 |
| ('Thank', 'you') | 386 |
| ('.', '``') | 358 |
| ('.', 'I') | 354 |
| ('.', 'Thank') | 337 |
| ('``', '@') | 320 |
| ('&', 'amp') | 290 |
のような、、、:)数字、記号を(無視する方法はありますか?テキストはつぶやきなので、#と@を除いて数字と記号は無視します。