Prerequisite: Extends 11: Databricks – Spark ML – Multivariate Linear Regression. How do you convert Pyspark dataframe to Pndas Dataframe? df.toPandas() converts Pyspark Dataframe to Pandas Dataframe.
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
from pyspark.sql.types import * input_data = ( (400,3,5,480000.00), (500,3,20,400000.00,), (600,5,None,850000.00), (700,4,10,770000.00), (800,4,15,800000.00), (1000,6,20,1100000.00), (1200,7,2,1600000.00) ) data_schema = [StructField('land_area', IntegerType(), False), StructField('bedrooms', IntegerType(), True), StructField('age', IntegerType(), True), StructField('house_price',DoubleType(),False)] final_struc = StructType(fields=data_schema) df = spark.sparkContext.parallelize(input_data) df_input= spark.createDataFrame(df, final_struc) pandas_df = df_input.toPandas() print(pandas_df) |
Output:
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
df_input:pyspark.sql.dataframe.DataFrame land_area:integer bedrooms:integer age:integer house_price:double land_area bedrooms age house_price 0 400 3 5.0 480000.0 1 500 3 20.0 400000.0 2 600 5 NaN 850000.0 3 700 4 10.0 770000.0 4 800 4 15.0 800000.0 5 1000 6 20.0 1100000.0 6 1200 7 2.0 1600000.0 |
How to perform statistical data exploration?… Read more ›...