aboutsummaryrefslogtreecommitdiff
path: root/python
diff options
context:
space:
mode:
Diffstat (limited to 'python')
-rw-r--r--python/pyspark/sql/group.py12
1 files changed, 8 insertions, 4 deletions
diff --git a/python/pyspark/sql/group.py b/python/pyspark/sql/group.py
index 227f40bc3c..d8ed7eb2dd 100644
--- a/python/pyspark/sql/group.py
+++ b/python/pyspark/sql/group.py
@@ -168,20 +168,24 @@ class GroupedData(object):
"""
@since(1.6)
- def pivot(self, pivot_col, *values):
+ def pivot(self, pivot_col, values=None):
"""Pivots a column of the current DataFrame and preform the specified aggregation.
:param pivot_col: Column to pivot
:param values: Optional list of values of pivotColumn that will be translated to columns in
the output data frame. If values are not provided the method with do an immediate call
to .distinct() on the pivot column.
- >>> df4.groupBy("year").pivot("course", "dotNET", "Java").sum("earnings").collect()
+
+ >>> df4.groupBy("year").pivot("course", ["dotNET", "Java"]).sum("earnings").collect()
[Row(year=2012, dotNET=15000, Java=20000), Row(year=2013, dotNET=48000, Java=30000)]
+
>>> df4.groupBy("year").pivot("course").sum("earnings").collect()
[Row(year=2012, Java=20000, dotNET=15000), Row(year=2013, Java=30000, dotNET=48000)]
"""
- jgd = self._jdf.pivot(_to_java_column(pivot_col),
- _to_seq(self.sql_ctx._sc, values, _create_column_from_literal))
+ if values is None:
+ jgd = self._jdf.pivot(pivot_col)
+ else:
+ jgd = self._jdf.pivot(pivot_col, values)
return GroupedData(jgd, self.sql_ctx)