finding the minimum using map reduce












0















Im trying to find the minimum of data set and was given this example to help. The code gives me the maximum. I cant find what to change to make it find the min.



from mrjob.job import MRJob

from mrjob.step import MRStep

class HighestRevenue(MRJob):

def mapper_get_city(self, key, line):
# create a key-value pair with key: city and value: amount
line_cols = line.split(',')
yield line_cols[0], float(line_cols[2])

def combiner_process_city(self, city, amount):
# consolidates all key-value pairs of mapper function (performed at mapper nodes)
yield city, sum(amount)

def reducer_city_amount(self, city, amount):
# final consolidation of key-value pairs at reducer nodes
yield None, (city, sum(amount))

def secondReducer(self, city, amount):
self.aList =
for a in amount:
self.aList.append(a)
self.aList.sort(key=lambda x: x[1], reverse=True)
for m in range(0,1):
yield self.aList[0]

def steps(self):
return [
MRStep(mapper = self.mapper_get_city,
combiner = self.combiner_process_city,
reducer = self.reducer_city_amount),
MRStep(reducer = self.secondReducer)
]









share|improve this question

























  • There is a good answer already. Just wanted to point out that in the future you might want to format your code in a nice way. And also try to post the minimal code snippet that is a working example, but can be understood very fast. These will increase the willingness of users to answer your question.

    – zsomko
    Nov 24 '18 at 18:15
















0















Im trying to find the minimum of data set and was given this example to help. The code gives me the maximum. I cant find what to change to make it find the min.



from mrjob.job import MRJob

from mrjob.step import MRStep

class HighestRevenue(MRJob):

def mapper_get_city(self, key, line):
# create a key-value pair with key: city and value: amount
line_cols = line.split(',')
yield line_cols[0], float(line_cols[2])

def combiner_process_city(self, city, amount):
# consolidates all key-value pairs of mapper function (performed at mapper nodes)
yield city, sum(amount)

def reducer_city_amount(self, city, amount):
# final consolidation of key-value pairs at reducer nodes
yield None, (city, sum(amount))

def secondReducer(self, city, amount):
self.aList =
for a in amount:
self.aList.append(a)
self.aList.sort(key=lambda x: x[1], reverse=True)
for m in range(0,1):
yield self.aList[0]

def steps(self):
return [
MRStep(mapper = self.mapper_get_city,
combiner = self.combiner_process_city,
reducer = self.reducer_city_amount),
MRStep(reducer = self.secondReducer)
]









share|improve this question

























  • There is a good answer already. Just wanted to point out that in the future you might want to format your code in a nice way. And also try to post the minimal code snippet that is a working example, but can be understood very fast. These will increase the willingness of users to answer your question.

    – zsomko
    Nov 24 '18 at 18:15














0












0








0








Im trying to find the minimum of data set and was given this example to help. The code gives me the maximum. I cant find what to change to make it find the min.



from mrjob.job import MRJob

from mrjob.step import MRStep

class HighestRevenue(MRJob):

def mapper_get_city(self, key, line):
# create a key-value pair with key: city and value: amount
line_cols = line.split(',')
yield line_cols[0], float(line_cols[2])

def combiner_process_city(self, city, amount):
# consolidates all key-value pairs of mapper function (performed at mapper nodes)
yield city, sum(amount)

def reducer_city_amount(self, city, amount):
# final consolidation of key-value pairs at reducer nodes
yield None, (city, sum(amount))

def secondReducer(self, city, amount):
self.aList =
for a in amount:
self.aList.append(a)
self.aList.sort(key=lambda x: x[1], reverse=True)
for m in range(0,1):
yield self.aList[0]

def steps(self):
return [
MRStep(mapper = self.mapper_get_city,
combiner = self.combiner_process_city,
reducer = self.reducer_city_amount),
MRStep(reducer = self.secondReducer)
]









share|improve this question
















Im trying to find the minimum of data set and was given this example to help. The code gives me the maximum. I cant find what to change to make it find the min.



from mrjob.job import MRJob

from mrjob.step import MRStep

class HighestRevenue(MRJob):

def mapper_get_city(self, key, line):
# create a key-value pair with key: city and value: amount
line_cols = line.split(',')
yield line_cols[0], float(line_cols[2])

def combiner_process_city(self, city, amount):
# consolidates all key-value pairs of mapper function (performed at mapper nodes)
yield city, sum(amount)

def reducer_city_amount(self, city, amount):
# final consolidation of key-value pairs at reducer nodes
yield None, (city, sum(amount))

def secondReducer(self, city, amount):
self.aList =
for a in amount:
self.aList.append(a)
self.aList.sort(key=lambda x: x[1], reverse=True)
for m in range(0,1):
yield self.aList[0]

def steps(self):
return [
MRStep(mapper = self.mapper_get_city,
combiner = self.combiner_process_city,
reducer = self.reducer_city_amount),
MRStep(reducer = self.secondReducer)
]






python mapreduce






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 24 '18 at 21:58









Sven Harris

1,7571211




1,7571211










asked Nov 24 '18 at 17:54









georgegeorge

31




31













  • There is a good answer already. Just wanted to point out that in the future you might want to format your code in a nice way. And also try to post the minimal code snippet that is a working example, but can be understood very fast. These will increase the willingness of users to answer your question.

    – zsomko
    Nov 24 '18 at 18:15



















  • There is a good answer already. Just wanted to point out that in the future you might want to format your code in a nice way. And also try to post the minimal code snippet that is a working example, but can be understood very fast. These will increase the willingness of users to answer your question.

    – zsomko
    Nov 24 '18 at 18:15

















There is a good answer already. Just wanted to point out that in the future you might want to format your code in a nice way. And also try to post the minimal code snippet that is a working example, but can be understood very fast. These will increase the willingness of users to answer your question.

– zsomko
Nov 24 '18 at 18:15





There is a good answer already. Just wanted to point out that in the future you might want to format your code in a nice way. And also try to post the minimal code snippet that is a working example, but can be understood very fast. These will increase the willingness of users to answer your question.

– zsomko
Nov 24 '18 at 18:15












1 Answer
1






active

oldest

votes


















1














remove reverse=True from sort procedure inside of secondReducer






share|improve this answer
























  • ty that solve the problem I was having. I assume that reverse statement just took the result as opposite.

    – george
    Nov 25 '18 at 7:18











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53460911%2ffinding-the-minimum-using-map-reduce%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









1














remove reverse=True from sort procedure inside of secondReducer






share|improve this answer
























  • ty that solve the problem I was having. I assume that reverse statement just took the result as opposite.

    – george
    Nov 25 '18 at 7:18
















1














remove reverse=True from sort procedure inside of secondReducer






share|improve this answer
























  • ty that solve the problem I was having. I assume that reverse statement just took the result as opposite.

    – george
    Nov 25 '18 at 7:18














1












1








1







remove reverse=True from sort procedure inside of secondReducer






share|improve this answer













remove reverse=True from sort procedure inside of secondReducer







share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 24 '18 at 18:08









mangustamangusta

1,63921326




1,63921326













  • ty that solve the problem I was having. I assume that reverse statement just took the result as opposite.

    – george
    Nov 25 '18 at 7:18



















  • ty that solve the problem I was having. I assume that reverse statement just took the result as opposite.

    – george
    Nov 25 '18 at 7:18

















ty that solve the problem I was having. I assume that reverse statement just took the result as opposite.

– george
Nov 25 '18 at 7:18





ty that solve the problem I was having. I assume that reverse statement just took the result as opposite.

– george
Nov 25 '18 at 7:18


















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53460911%2ffinding-the-minimum-using-map-reduce%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

A CLEAN and SIMPLE way to add appendices to Table of Contents and bookmarks

Calculate evaluation metrics using cross_val_predict sklearn

Insert data from modal to MySQL (multiple modal on website)