使用map reduce找到最小值

时间:2018-11-24 17:54:21

标签: python mapreduce

我正在尝试查找数据集的最小值,并给出了此示例来提供帮助。该代码给了我最大的价值。我找不到要更改的内容以使其成为最小值。

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)
             ]

1 个答案:

答案 0 :(得分:1)

pyodbc.OperationalError: ('08001', '[08001] [Microsoft][ODBC Driver 13 for SQL Server]TCP Provider: No connection could be made because the target machine actively refused it.\r\n (10061) (SQLDriverConnect); [08001] [Microsoft][ODBC Driver 13 for SQL Server]Login timeout expired (0); [08001] [Microsoft][ODBC Driver 13 for SQL Server]Invalid connection string attribute (0); [08001] [Microsoft][ODBC Driver 13 for SQL Server]A network-related or instance-specific error has occurred while establishing a connection to SQL Server. Server is not found or not accessible. Check if instance name is correct and if SQL Server is configured to allow remote connections. For more information see SQL Server Books Online. (10061)')内的reverse=True过程中删除sort