コード例 #1
0
 def test_groupby(self):
     a = Babe().pull(stream=StringIO('a,b\n1,2\n3,4\n1,4\n'),
                     format="csv").typedetect()
     a = a.groupBy(key="a",
                   reducer=lambda key, rows:
                   (key, sum([row.b for row in rows])))
     buf = StringIO()
     a.push(stream=buf, format='csv')
     self.assertEquals(buf.getvalue(), "a,b\n1,6\n3,4\n")
コード例 #2
0
ファイル: wordcount.py プロジェクト: waytai/PyBabe
def wordcount():
    a = Babe().pull(protocol='http',
                    host='www.ietf.org',
                    filename='rfc/rfc1149.txt')
    a = a.flatMap(lambda row: [(w, 1) for w in re.findall('\w+', row.text)],
                  columns=['word', 'count'])
    a = a.groupBy(key='word',
                  reducer=lambda word, rows:
                  (word, sum([row.count for row in rows])))
    a = a.maxN(column='count', n=10)
    a.push(stream=sys.stdout, format='csv')
コード例 #3
0
def wordcount():
    a = Babe().pull(protocol='http',
                    host='www.ietf.org',
                    filename='rfc/rfc1149.txt')
    a = a.flatMap(lambda row: [(w, 1) for w in re.findall('\w+', row.text)],
                  columns=['word', 'count'])
    a = a.groupBy(key='word',
                  reducer=lambda word, rows: (word, sum([row.count for row in rows])))
    a = a.maxN(column='count',
               n=10)
    a.push(stream=sys.stdout,
           format='csv')
コード例 #4
0
ファイル: tests.py プロジェクト: nizox/PyBabe
 def test_groupby(self):
     a = Babe().pull(stream=StringIO('a,b\n1,2\n3,4\n1,4\n'), format="csv").typedetect()
     a = a.groupBy(key="a", reducer=lambda key, rows: (key, sum([row.b for row in rows])))
     buf = StringIO()
     a.push(stream=buf, format='csv')
     self.assertEquals(buf.getvalue(), "a,b\n1,6\n3,4\n")