简体   繁体   English

我正在尝试编写一个 python 脚本来使用 Mapreducer 读取 csv 并且我收到错误 ValueError: too many values to unpack (expected 2)

[英]I'm trying to write a python script to read a csv using Mapreducer and im getting the error ValueError: too many values to unpack (expected 2)

0 0

I'm running the following Python code in MapReduce:我在 MapReduce 中运行以下 Python 代码:

from mrjob.job import MRJob
from mrjob.step import MRStep


class productRevenue(MRJob):
    #each input lines consists of product, productCategory, price, and paymentMode
    def mapper_get_product(self, _, line):
        # create a key-value pair with key: product and value: price
        line_cols = line.split(',')
        yield line_cols[1], float(line_cols[2])

    def combiner_count_product(self, product, counts):
        # consolidates all key-value pairs of mapper function (performed at mapper nodes)
        yield product, sum(counts)

    def reducer_count_product(self, product, counts):
        # final consolidation of key-value pairs at reducer nodes
        yield None, '${:,.2f}'.format(sum(counts), product)

    def reducer_find_max(self, _, product_count_pairs):
        yield max(product_count_pairs)

    def steps(self):
        return [
            MRStep(mapper=self.mapper_get_product,
                   combiner=self.combiner_count_product,
                   reducer=self.reducer_count_product),
            MRStep(reducer=self.reducer_find_max)
        ]       

if __name__ == '__main__':
    productRevenue.run()

I get the error: ValueError: too many values to unpack (expected 2) but I can't figure out why.我收到错误:ValueError: too many values to unpack (expected 2) 但我不知道为什么。 Any suggestions?有什么建议? The cmd line code I'm running is: python test.py data.csv The .CSV can be download here https://users.cs.fiu.edu/~prabakar/database/4722sp19/abarr054-3495916/我正在运行的 cmd 行代码是:python test.py data.csv .CSV 可以在这里下载https://users.cs.fiu.edu/~prabakar/database/4722sp19/abarr054-3495916/

In reducer_find_max() function, you are passing one parameter in yield.在 reducer_find_max() 函数中,您在 yield 中传递一个参数。 The yield function basically outputs a key and a value. yield 函数基本上输出一个键和一个值。

Please pass two parameters as "yield max(product_count_pairs), None"请传递两个参数作为“yield max(product_count_pairs), None”

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 收到错误:ValueError:要解包的值太多(预期为 2) - Getting an error: ValueError: too many values to unpack (expected 2) python:ValueError:太多值无法解包(预期2) - python: ValueError: too many values to unpack (expected 2) 出现错误:ValueError:要解包的值太多(预期为 5) - Getting error: ValueError: too many values to unpack (expected 5) 为什么我会收到此 ValueError:要解压的值太多(预期为 3)? - Why am I getting this ValueError: too many values to unpack (expected 3)? 如何传递此错误“ValueError:在 Python 中解压的值太多(预期为 2)? - How Pass This Error " ValueError: too many values to unpack (expected 2) in Python? 错误:ValueError:解包的值太多(预期为 3) - Error: ValueError: too many values to unpack (expected 3) Python - ValueError:解压缩的值太多(预期2) - Python - ValueError: too many values to unpack (expected 2) Python ValueError:太多值无法解包(预期2) - Python ValueError: too many values to unpack (expected 2) Python ValueError:要解压的值太多(预期为 3) - Python ValueError: too many values to unpack (expected 3) 我想解决错误“ValueError: too many values to unpack (expected 2)” - I want to resolve the error “ValueError: too many values to unpack (expected 2)”
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM