To select a column from the database table, we first need to make our dataframe accessible in our SQL queries. To do this, we call the df.createOrReplaceTempView method and set the temporary view name to insurance_df.
df.createOrReplaceTempView("insurance_df")
df2 = spark.sql("SELECT AGE, SEX FROM insurance_df")
df2.show()
To select a column from the database table, we first need to make our dataframe accessible in our SQL queries. To do this, we call the df.createOrReplaceTempView method and set the temporary view name to insurance_df.
df.createOrReplaceTempView("insurance_df")
df2 = spark.sql("SELECT AGE, SEX FROM insurance_df")
df2.show()