In this question don’t change code, just in python postgreSQL but solve the question and follow the instructions

Np Ms Office 365/Excel 2016 I Ntermed
1st Edition
ISBN:9781337508841
Author:Carey
Publisher:Carey
Chapter5: Working With Excel Tables, Pivottables, And Pivotcharts
Section: Chapter Questions
Problem 11RA
icon
Related questions
Question
100%

In this question don’t change code, just in python postgreSQL but solve the question and follow the instructions

#!/usr/bin/env python
from operator import itemgetter
import sys
current_word = None
current_count = 0
word = None
# input comes from STDIN
for line in sys.stdin:
# remove leading and trailing whitespace
line = line.strip()
# parse the input we got from mapper.py
word, count = line.split('\t', 1)'
# print "DEBUG: "
# convert count (currently a string) to int
try:
count = int(count)
except ValueError:
# count was not a number, normally we would drop a log error
# but that is out of scope here, so continue
continue
word, " "
count
# this IF-switch only works because Hadoop sorts
# by key (here: word) before it is passed to the reducer
# hence the single-host example using streaming pipe must add in
# an explicit sort!
if current_word == word:
current_count += count
else:
if current_word:
output
# write result to STDOUT
print(f'{current_word}\t{current_count}')
current_count = count
current_word = word
# do not forget to output the last word if needed!
if current_word == word:
print(f'{current_word}\t{current_count}')
$ cat beach_day.csv I ./mapper.py | sort -k1,1 | ./reducer.py
"Accessory"
"Camping"
"Food"
"Toy"
1
2
Transcribed Image Text:#!/usr/bin/env python from operator import itemgetter import sys current_word = None current_count = 0 word = None # input comes from STDIN for line in sys.stdin: # remove leading and trailing whitespace line = line.strip() # parse the input we got from mapper.py word, count = line.split('\t', 1)' # print "DEBUG: " # convert count (currently a string) to int try: count = int(count) except ValueError: # count was not a number, normally we would drop a log error # but that is out of scope here, so continue continue word, " " count # this IF-switch only works because Hadoop sorts # by key (here: word) before it is passed to the reducer # hence the single-host example using streaming pipe must add in # an explicit sort! if current_word == word: current_count += count else: if current_word: output # write result to STDOUT print(f'{current_word}\t{current_count}') current_count = count current_word = word # do not forget to output the last word if needed! if current_word == word: print(f'{current_word}\t{current_count}') $ cat beach_day.csv I ./mapper.py | sort -k1,1 | ./reducer.py "Accessory" "Camping" "Food" "Toy" 1 2
Pseudo Code:
1. For each record in my data set:
a. Inspect the column listed in the group by statement, and determine if we have found it previously,
b. If we have not then put it into a data structure which keeps track of keys and can associate values with them, such as a "map" (also called a hash, or dictionary) and put the aggregate function target (price) value into the value spot.
c. If we have seen it before, then take the value from our aggregate function target (again, price) and apply the function to it before replacing the new value with the one curently in the value spot of our map.
Transcribed Image Text:Pseudo Code: 1. For each record in my data set: a. Inspect the column listed in the group by statement, and determine if we have found it previously, b. If we have not then put it into a data structure which keeps track of keys and can associate values with them, such as a "map" (also called a hash, or dictionary) and put the aggregate function target (price) value into the value spot. c. If we have seen it before, then take the value from our aggregate function target (again, price) and apply the function to it before replacing the new value with the one curently in the value spot of our map.
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Structured English
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Np Ms Office 365/Excel 2016 I Ntermed
Np Ms Office 365/Excel 2016 I Ntermed
Computer Science
ISBN:
9781337508841
Author:
Carey
Publisher:
Cengage