pyspark.sql.DataFrame.toDF¶
-
DataFrame.
toDF
(*cols: str) → pyspark.sql.dataframe.DataFrame[source]¶ Returns a new
DataFrame
that with new specified column namesNew in version 1.6.0.
Changed in version 3.4.0: Supports Spark Connect.
- Parameters
- *colstuple
a tuple of string new column name. The length of the list needs to be the same as the number of columns in the initial
DataFrame
- Returns
DataFrame
DataFrame with new column names.
Examples
>>> df = spark.createDataFrame([(14, "Tom"), (23, "Alice"), ... (16, "Bob")], ["age", "name"]) >>> df.toDF('f1', 'f2').show() +---+-----+ | f1| f2| +---+-----+ | 14| Tom| | 23|Alice| | 16| Bob| +---+-----+