実際、私はhadoopとpythonも初めてです....だから私の疑問は、hadoopでpythonスクリプトを実行する方法です.....また、pythonを使用してwordcountプログラムを書いていました..だから、このスクリプトを実行できますかmap reduce を使用して .... 実際にコードを書きました。以下のような出力を見ることができます。 Darkness 1 Heaven 2 It 3 Light 4 age 5 age 6 all 7 all 8 authority 9 before 10 before 11 being 12 信念 13 best 14 comparison 15程度 16 絶望 17 直接 18 直接 19
It is counting number of words in a list..but whati have to achieve is grouping and deleting the duplicates and also count number of times of its occurrences .....
Below is my code . can somebody please tell me where i have done the mistake
********************************************************
Wordcount.py
********************************************************
import urllib2
import random
from operator import itemgetter
current_word = {}
current_count = 0
story = 'http://sixty-north.com/c/t.txt'
request = urllib2.Request(story)
response = urllib2.urlopen(request)
each_word = []
words = None
count = 1
same_words ={}
word = []
""" looping the entire file """
for line in response:
line_words = line.split()
for word in line_words: # looping each line and extracting words
each_word.append(word)
random.shuffle(each_word)
Sort_word = sorted(each_word)
for words in Sort_word:
same_words = words.lower(),int(count)
#print same_words
#print words
if not words in current_word :
current_count = current_count +1
print '%s\t%s' % (words, current_count)
else:
current_count = 1
#if Sort_word == words.lower():
#current_count += count
current_count = count
current_word = word
#print '2. %s\t%s' % (words, current_count)