Skip to content

Commit ed40ab5

Browse files
committed
[SPARK-7509][SQL] DataFrame.drop in Python for dropping columns.
Author: Reynold Xin <[email protected]> Closes apache#6068 from rxin/drop-column and squashes the following commits: 9d7d5ec [Reynold Xin] [SPARK-7509][SQL] DataFrame.drop in Python for dropping columns. (cherry picked from commit 028ad4b) Signed-off-by: Reynold Xin <[email protected]>
1 parent c30982d commit ed40ab5

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

python/pyspark/sql/dataframe.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1014,7 +1014,7 @@ def withColumn(self, colName, col):
10141014

10151015
@ignore_unicode_prefix
10161016
def withColumnRenamed(self, existing, new):
1017-
"""REturns a new :class:`DataFrame` by renaming an existing column.
1017+
"""Returns a new :class:`DataFrame` by renaming an existing column.
10181018
10191019
:param existing: string, name of the existing column to rename.
10201020
:param col: string, new name of the column.
@@ -1027,6 +1027,18 @@ def withColumnRenamed(self, existing, new):
10271027
for c in self.columns]
10281028
return self.select(*cols)
10291029

1030+
@ignore_unicode_prefix
1031+
def drop(self, colName):
1032+
"""Returns a new :class:`DataFrame` that drops the specified column.
1033+
1034+
:param colName: string, name of the column to drop.
1035+
1036+
>>> df.drop('age').collect()
1037+
[Row(name=u'Alice'), Row(name=u'Bob')]
1038+
"""
1039+
jdf = self._jdf.drop(colName)
1040+
return DataFrame(jdf, self.sql_ctx)
1041+
10301042
def toPandas(self):
10311043
"""Returns the contents of this :class:`DataFrame` as Pandas ``pandas.DataFrame``.
10321044

0 commit comments

Comments
 (0)