Python 2.7 python中的Mapreduce字数

Python 2.7 python中的Mapreduce字数,python-2.7,csv,mapreduce,word-count,Python 2.7,Csv,Mapreduce,Word Count,我不熟悉mapreducer程序。所以当我搜索mapreducer程序的示例时,我得到的只是单词计数程序。所有与字数计算相关的程序都使用要归档的文本作为输入。我尝试使用一个csv文件作为输入,但是减速机不能像处理文本文件那样工作。 这就是我现在看到的例子。有人能解释一下原因吗?您可以使用该类: 在文档中,您会发现许多更有用的信息。区分 :用于并行执行的编程模型 Python:一种编程语言 Hadoop:Python可以运行的集群平台 你真的需要Hadoop的MapReduce还是仅仅是一个纯Py

我不熟悉mapreducer程序。所以当我搜索mapreducer程序的示例时,我得到的只是单词计数程序。所有与字数计算相关的程序都使用要归档的文本作为输入。我尝试使用一个csv文件作为输入,但是减速机不能像处理文本文件那样工作。 这就是我现在看到的例子。有人能解释一下原因吗?

您可以使用该类:

在文档中,您会发现许多更有用的信息。

区分

:用于并行执行的编程模型 Python:一种编程语言 Hadoop:Python可以运行的集群平台 你真的需要Hadoop的MapReduce还是仅仅是一个纯Python的例子?如果是后者,它可能比您的链接容易得多:

import multiprocessing
def word_count(line, delimiter=","):
    """Worker"""
    summary = {}
    for word in line.strip().split(delimiter):
        if word in summary:
            summary[word] += 1
        else:
            summary[word] = 1
    return summary
pool = multiprocessing.Pool()
result = {}
# Map: each line to a separate worker
for summary in pool.imap_unordered(word_count, open("/path/to/file.csv")):
    # Reduce: aggregate the result of each line into one result
    for (word, count) in summary.items():
        result[word] = result[word]+count if word in result else count
print(result)

谢谢你的帮助。但我的怀疑是不同的。我正在尝试mapreduce程序。由于我目前正在Hadoop平台上工作,我想了解更多关于mapreduce程序的信息。因此,我想知道这个范例的答案。不过,感谢您的帮助:
import multiprocessing
def word_count(line, delimiter=","):
    """Worker"""
    summary = {}
    for word in line.strip().split(delimiter):
        if word in summary:
            summary[word] += 1
        else:
            summary[word] = 1
    return summary
pool = multiprocessing.Pool()
result = {}
# Map: each line to a separate worker
for summary in pool.imap_unordered(word_count, open("/path/to/file.csv")):
    # Reduce: aggregate the result of each line into one result
    for (word, count) in summary.items():
        result[word] = result[word]+count if word in result else count
print(result)