【问题标题】:Hadoop map reduce removing values less than or more than in mapperHadoop map reduce删除小于或大于mapper中的值
【发布时间】:2017-02-19 04:46:34
【问题描述】:
#!/usr/bin/env python

import sys

# input comes from STDIN (standard input)
for line in sys.stdin:
    line = line.strip()
    words = line.split()
    fulldate = words[1]
    year = fulldate[0:4]
    print '%s\t%s' % (year, words[15])

在 words[15] 中映射的值是来自第 16 列(或 15 表示计算机计数。0-15)的 txt 文件中的温度值。 ftp://ftp.ncdc.noaa.gov/pub/data/uscrn/products/daily01/2010/CRND0103-2010-AK_St._Paul_4_NE.txt

如您所见,前 10-20 个结果显示 -9999。其余的是 0 到 100 之间的数字。

我想在发送到减速器之前过滤掉这些 -9999 值。我怎样才能做到这一点?

【问题讨论】:

    标签: hadoop dictionary reduce


    【解决方案1】:

    跳过你不想要的应该很简单。如果该值不在您想要的范围内,请不要打印它,例如:

    #!/usr/bin/env python
    
    import sys
    
    # input comes from STDIN (standard input)
    for line in sys.stdin:
        line = line.strip()
        words = line.split()
        fulldate = words[1]
        year = fulldate[0:4]
        if words[15] >= 0 && words[15] <= 100
            print '%s\t%s' % (year, words[15])
    

    如果应用程序需要,可以不为每个输入记录生成输出,或者甚至为每个输入生成多个输出记录(通过多次打印)。

    【讨论】:

      猜你喜欢
      • 2023-03-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-07-07
      • 1970-01-01
      • 2011-07-21
      相关资源
      最近更新 更多