Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

Convert PySpark RDD to DataFrame

# importing necessary libraries
from pyspark.sql import SparkSession
  
# function to create new SparkSession
def create_session():
    spk = SparkSession.builder 
        .appName("Corona_cases_statewise.com") 
        .getOrCreate()
    return spk
  
# function to create RDD
def create_RDD(sc_obj, data):
    df = sc.parallelize(data)
    return df
  
  
if __name__ == "__main__":
  
    input_data = [("Uttar Pradesh", 122000, 89600, 12238),
                  ("Maharashtra", 454000, 380000, 67985),
                  ("Tamil Nadu", 115000, 102000, 13933),
                  ("Karnataka", 147000, 111000, 15306),
                  ("Kerala", 153000, 124000, 5259)]
  
    # calling function to create SparkSession
    spark = create_session()
  
    # creating spark context object
    sc = spark.sparkContext
  
    # calling function to create RDD
    rd_df = create_RDD(sc, input_data)
  
    # printing the type
    print(type(rd_df))
Comment

PREVIOUS NEXT
Code Example
Python :: python null check optional 
Python :: python get the X charecters at the end of a string 
Python :: bbc weather webscraping python beautifulsoup 
Python :: python datetime toordinal 
Python :: The float type in Python3 can represent decimal 0.1 without error. 
Python :: Create Admin Interface For Objects 
Python :: python keyword search engine 
Python :: logged_passengers 
Python :: valueerror python list 
Python :: How to swapcase of string in python 
Python :: python print list of keywords 
Python :: django url wildcard 
Python :: flask docker redirect container name 
Python :: jntuk r20 1-2 python lab manual 
Python :: os cd python 
Python :: flask in colab ngrok error 
Python :: how to reassign a key py 
Python :: python get all the items list 
Python :: django create view template 
Python :: how do i re-restablish the third reich 
Python :: animal quiz game in python 
Python :: python string with si suffix to number 
Python :: python selenium firefox handle ssl bypass 
Python :: truc python 
Python :: plot a against b 
Python :: Tape Equilibrium 
Python :: insert python 
Python :: pyqt-opengl-drawing-simple-scenes 
Python :: Ignoring NaNs with str.contains 
Python :: remove special characters and numbers from string python 
ADD CONTENT
Topic
Content
Source link
Name
9+9 =