Skip to content

Commit 9d7d5ec

Browse files
committed
[SPARK-7509][SQL] DataFrame.drop in Python for dropping columns.
1 parent 57255dc commit 9d7d5ec

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
@@ -986,7 +986,7 @@ def withColumn(self, colName, col):
986986

987987
@ignore_unicode_prefix
988988
def withColumnRenamed(self, existing, new):
989-
"""REturns a new :class:`DataFrame` by renaming an existing column.
989+
"""Returns a new :class:`DataFrame` by renaming an existing column.
990990
991991
:param existing: string, name of the existing column to rename.
992992
:param col: string, new name of the column.
@@ -999,6 +999,18 @@ def withColumnRenamed(self, existing, new):
999999
for c in self.columns]
10001000
return self.select(*cols)
10011001

1002+
@ignore_unicode_prefix
1003+
def drop(self, colName):
1004+
"""Returns a new :class:`DataFrame` that drops the specified column.
1005+
1006+
:param colName: string, name of the column to drop.
1007+
1008+
>>> df.drop('age').collect()
1009+
[Row(name=u'Alice'), Row(name=u'Bob')]
1010+
"""
1011+
jdf = self._jdf.drop(colName)
1012+
return DataFrame(jdf, self.sql_ctx)
1013+
10021014
def toPandas(self):
10031015
"""Returns the contents of this :class:`DataFrame` as Pandas ``pandas.DataFrame``.
10041016

0 commit comments

Comments
 (0)