How to create a PySpark dataframe from multiple lists ?
In this article, we will discuss how to create Pyspark dataframe from multiple lists.
- 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)
Example 1: Python program to create two lists and create the dataframe using these two lists
Example 2: Python program to create 4 lists and create the dataframe
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course. And to begin with your Machine Learning Journey, join the Machine Learning – Basic Level Course