zoukankan      html  css  js  c++  java
  • [Spark][Python]获得 key,value形式的 RDD

    [Spark][Python]获得 key,value形式的 RDD


    [training@localhost ~]$ cat users.txt
    user001 Fred Flintstone
    user090 Bugs Bunny
    user111 Harry Potter
    [training@localhost ~]$ hdfs dfs -put users.txt
    [training@localhost ~]$
    [training@localhost ~]$
    [training@localhost ~]$ hdfs dfs -cat users.txt
    user001 Fred Flintstone  <<<<<<<<<<<<<<<<<<,  tab 符 分隔
    user090 Bugs Bunny
    user111 Harry Potter
    [training@localhost ~]$

     user01 = sc.textFile("users.txt")

    user02 = user01.map(lambda line : line.split(" "))

    In [16]: user02.take(3)
    Out[16]:
    [[u'user001', u'Fred Flintstone'],
    [u'user090', u'Bugs Bunny'],
    [u'user111', u'Harry Potter']]

    user03 = user02.map(lambda fields: (fields[0],fields[1]))

    user03.take(3)

    Out[20]:
    [(u'user001', u'Fred Flintstone'), <<<<<<<<<<<<<<<< 此处构筑了 key-value pair
    (u'user090', u'Bugs Bunny'),
    (u'user111', u'Harry Potter')]

  • 相关阅读:
    tricky c++ new(this)
    MCI使用
    LoadIcon的使用
    深入浅出Node.js (2)
    洛谷 P1464 Function
    洛谷 P1722 矩阵 II
    洛谷 P1036 选数
    洛谷 P1303 A*B Problem
    洛谷 P2694 接金币
    洛谷 P1679 神奇的四次方数
  • 原文地址:https://www.cnblogs.com/gaojian/p/008-Aggregating-Data-with-Pair-RDDs.html
Copyright © 2011-2022 走看看