Skip to content

Commit

Permalink
flatMap
Browse files Browse the repository at this point in the history
  • Loading branch information
Davies Liu authored and rxin committed Feb 13, 2015
1 parent c4afb8e commit fe1267a
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions python/pyspark/sql/dataframe.py
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,17 @@ def map(self, f):
"""
return self.rdd.map(f)

def flatMap(self, f):
""" Return a new RDD by first applying a function to all elements of this,
and then flattening the results.
It's a shorthand for df.rdd.flatMap()
>>> df.flatMap(lambda p: p.name).collect()
[u'A', u'l', u'i', u'c', u'e', u'B', u'o', u'b']
"""
return self.rdd.flatMap(f)

def mapPartitions(self, f, preservesPartitioning=False):
"""
Return a new RDD by applying a function to each partition.
Expand Down

0 comments on commit fe1267a

Please sign in to comment.