Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

Excel to Pandas (Zillow) - Advanced Operations

Now that you’ve completed Excel_to_Pandas_Zillow_Basic.ipynb, you’re ready to build on those fundamentals in this advanced tutorial with more complex transformations, joins, and visual analysis.


Professor: Khai Lu
Developer: Rinrada Maneenop
Estimated Time: ~15 minutes


Contents:

  • Advanced Operations

    • PIVOT TABLES → pivot_table() and groupby()

    • JOINs → merge() with home_values + rent_values datasets

  • Data Visualization

    • Bar Charts

    • Line Charts

  • Interactive Widgets and Practice

Please run the cell below to import necessary variables we have defined earlier in the Excel_to_Pandas_Zillow_Basic.ipynb tutorial.

PIVOT TABLES → pivot_table() and groupby()

Pivot tables are one of Excel’s most powerful features for summarizing data.

Excel: Insert → PivotTable → Drag fields
Pandas: df.pivot_table() or df.groupby()

Pivot: median home value by market tier

  • Copy the latest snapshot with MarketTier classifications

  • Build a pivot of median HomeValue by MarketTier

  • Compare results to an equivalent groupby aggregation

Advanced pivot: State × Market Tier

  • Build a 2D pivot counting metros by state and market tier

  • Restrict to states with at least 5 metros for readability

  • Similar to an Excel pivot table with rows, columns, and counts


Calculating Change Over Time — pct_change() vs Excel Formulas

Excel Formula: =(B2-A2)/A2 for percent change between two cells
Pandas: .pct_change() — applies the formula across an entire column at once

Year-over-year (YoY) home value change

  • Calculate YoY change for each metro using current vs prior year values

  • In Excel this would require many repeated formulas

  • In pandas we can compute it for all metros in a few steps


JOINs → merge() with home_values + rent_values

In Excel, you might use VLOOKUP or Power Query to combine tables. In Pandas, we use merge() which offers SQL-style joins.

Types of Joins:

  • Left Join: Keep all rows from the left table, match where possible

  • Inner Join: Keep only rows that match in both tables

  • Outer Join: Keep all rows from both tables, fill NaN where no match

Prepare snapshots for joins

  • Filter home_values to the latest date and keep key columns

  • Filter rent_values to the latest date and keep rent information

  • These snapshots will be joined on RegionName

Left join: keep all home_values metros

  • Attach rent data from rent_values where available

  • Metros without rent data will have NaN in the Rent column

Inner join: metros in both datasets

  • Join home_values and rent_values only where the metro appears in both

  • Equivalent to Excel or SQL inner join on RegionName

After merging, calculate derived metrics

  • Price-to-Rent Ratio: how many years of rent equals the home value

  • Excel: =HomeValue / (Rent * 12)

  • Pandas: compute annual rent and price-to-rent for each metro


Data Visualization

Excel charts are great for quick visualizations. Pandas + Matplotlib/Seaborn offer much more customization and are fully reproducible!

Excel: Select data → Insert → Chart
Pandas: df.plot() or matplotlib/seaborn functions

Bar Charts

Line Charts


Quick Reference Cheat Sheet

Excel FeaturePandas EquivalentZillow Example
PivotTablepivot_table()Median home value by market tier
PivotTable (alt)groupby().agg()Same summary without pivot UI
Pivot with totalsmargins=TrueAdd Grand Total row/column
Pivot with multiple statsaggfunc=['mean','median','count']Tier-level summary stats
Interactive pivotpivot_table() + widgetsChange rows/cols/metric dynamically
JOIN tablesmerge(..., how='left')Keep all home-value metros
Inner joinmerge(..., how='inner')Keep metros present in both datasets
Calculated fieldNew column assignmentPrice-to-rent ratio and buy/rent signal
=(B-A)/A.pct_change()YoY home-value growth
Insert → Bar Chartplot(kind='bar')State/tier comparisons
Insert → Line Chartplot(kind='line')Time-series home-value trends
Chart labels/formatplt.title(), plt.grid(), annotationsImprove readability of Zillow charts