From 05c4bdb57947f44924b4fbdd8e4e2101f2f816f5 Mon Sep 17 00:00:00 2001 From: Jeff Zhang Date: Mon, 26 Oct 2015 09:25:19 +0100 Subject: [SPARK-11279][PYSPARK] Add DataFrame#toDF in PySpark Author: Jeff Zhang Closes #9248 from zjffdu/SPARK-11279. --- python/pyspark/sql/dataframe.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'python/pyspark/sql') diff --git a/python/pyspark/sql/dataframe.py b/python/pyspark/sql/dataframe.py index 36fc6e0611..3baff81477 100644 --- a/python/pyspark/sql/dataframe.py +++ b/python/pyspark/sql/dataframe.py @@ -1266,6 +1266,18 @@ class DataFrame(object): raise TypeError("col should be a string or a Column") return DataFrame(jdf, self.sql_ctx) + @ignore_unicode_prefix + def toDF(self, *cols): + """Returns a new class:`DataFrame` that with new specified column names + + :param cols: list of new column names (string) + + >>> df.toDF('f1', 'f2').collect() + [Row(f1=2, f2=u'Alice'), Row(f1=5, f2=u'Bob')] + """ + jdf = self._jdf.toDF(self._jseq(cols)) + return DataFrame(jdf, self.sql_ctx) + @since(1.3) def toPandas(self): """Returns the contents of this :class:`DataFrame` as Pandas ``pandas.DataFrame``. -- cgit v1.2.3