In this challenge, you'll use your knowledge of SparkSQL to determine key metrics about home sales data. Then you'll use Spark to create temporary views, partition the data, cache and uncache a temporary table, and verify that the table has been uncached.
Note: While there are two Jupyter Notebook formated files and both have the same code, the 'Home_Sales_colab.ipynb' was the were I ran the code via Google Colab. Therefore it's the only one of these two files that has the output to the queries.
- Content of the repository
- Instructions for the Project
- References
- Home_Sales.ipynb
- Home_Sales_colab.ipynb <-- This is the Jupyter Notebook that I actually worked on via Google Colab, thus it has the outputs to each cell of code.
- Rename the Home_Sales_starter_code.ipynb file as Home_Sales.ipynb
- Import the necessary PySpark SQL functions for this assignment.
- Read the home_sales_revised.csv data in the starter code into a Spark DataFrame.
- Create a temporary table called home_sales
- Answer the following questions using SparkSQL:
- What is the average price for a four-bedroom house sold for each year? Round off your answer to two decimal places
- What is the average price of a home for each year the home was built, that has three bedrooms and three bathrooms? Round off your answer to two decimal places.
- What is the average price of a home for each year the home was built, that has three betrooms, three bathrooms, two floors, and is greater than or equal to 2,000 square feet? Round off your answer to two decimal places.
- What is the average price of a home per "view" rating having an average home price greater than or equal to $350,000? Determine the run time for thi squery, and round off your naswer to two decimal places.
- Cache your temporary table home_sales
- Check if your temporary table is cached.
- Using the cached data, run the last query that calculates the average price of a home per "view" rating having an average home price greater than or equal to $350,000. Determine the runtime and compare it to uncached runtime.
- Partition by the "date_built" field on the formatted parquet home sales data.
- Create a temporary table for the parquet data.
- Run the last query that calculates the average price of a home per "view" rating having an average home price greater than or equal to $350,000. Determine the runtime and compare it to uncached runtime.
- Uncache the home_sales temporary table
- Verify that the home_sales temporary table is uncached using PySpark.
- Download your Home_sales.ipynb file and upload it to your "Home_Sales" GitHub repository.
- (NOTE: I worked on the colab version due to the packages installed and the size of the data. Therefore this is the file with the outputs).
Everything included in this project was covered in class. Regardless, these two resources were used to complete the challenge.
- Number Padding in PySpark Dataframes: https://stackoverflow.com/questions/45400829/padding-in-a-pyspark-dataframe