VOOZH about

URL: https://www.geeksforgeeks.org/python/how-to-create-a-pyspark-dataframe-from-multiple-lists/

⇱ How to create a PySpark dataframe from multiple lists ? - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

How to create a PySpark dataframe from multiple lists ?

Last Updated : 30 May, 2021

In this article, we will discuss how to create Pyspark dataframe from multiple lists. 

Approach

  • Create data from multiple lists and give column names in another list. So, to do our task we will use the zip method.

zip(list1,list2,., list n)

  • Pass this zipped data to spark.createDataFrame() method

dataframe = spark.createDataFrame(data, columns)

Examples

Example 1: Python program to create two lists and create the dataframe using these two lists

Output:

👁 Image

Example 2: Python program to create 4 lists and create the dataframe

Output:

👁 Image
Comment
Article Tags: