Skip to content

Commit 36282f7

Browse files
arayyhuai
authored andcommitted
[SPARK-12184][PYTHON] Make python api doc for pivot consistant with scala doc
In SPARK-11946 the API for pivot was changed a bit and got updated doc, the doc changes were not made for the python api though. This PR updates the python doc to be consistent. Author: Andrew Ray <ray.andrew@gmail.com> Closes apache#10176 from aray/sql-pivot-python-doc.
1 parent 84b8094 commit 36282f7

1 file changed

Lines changed: 9 additions & 5 deletions

File tree

python/pyspark/sql/group.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -169,16 +169,20 @@ def sum(self, *cols):
169169

170170
@since(1.6)
171171
def pivot(self, pivot_col, values=None):
172-
"""Pivots a column of the current DataFrame and perform the specified aggregation.
172+
"""
173+
Pivots a column of the current [[DataFrame]] and perform the specified aggregation.
174+
There are two versions of pivot function: one that requires the caller to specify the list
175+
of distinct values to pivot on, and one that does not. The latter is more concise but less
176+
efficient, because Spark needs to first compute the list of distinct values internally.
173177
174-
:param pivot_col: Column to pivot
175-
:param values: Optional list of values of pivot column that will be translated to columns in
176-
the output DataFrame. If values are not provided the method will do an immediate call
177-
to .distinct() on the pivot column.
178+
:param pivot_col: Name of the column to pivot.
179+
:param values: List of values that will be translated to columns in the output DataFrame.
178180
181+
// Compute the sum of earnings for each year by course with each course as a separate column
179182
>>> df4.groupBy("year").pivot("course", ["dotNET", "Java"]).sum("earnings").collect()
180183
[Row(year=2012, dotNET=15000, Java=20000), Row(year=2013, dotNET=48000, Java=30000)]
181184
185+
// Or without specifying column values (less efficient)
182186
>>> df4.groupBy("year").pivot("course").sum("earnings").collect()
183187
[Row(year=2012, Java=20000, dotNET=15000), Row(year=2013, Java=30000, dotNET=48000)]
184188
"""

0 commit comments

Comments
 (0)