Housing Data: Subset Stats, Filtering, Percentiles and an OLS Fit

MediumData Wrangling

Reported in interviews at Proxify

Problem statement

A take-home data task gives you a small housing table. Each row is one sold house with nine numeric columns: Price (sale price in thousands of USD), Bedroom, Space (living area in square feet), Room, Lot (lot width in feet), Tax (annual property tax in USD), Bathroom, Garage (spaces) and Condition (1 if recently renovated, else 0). Some values are missing (None); Price is never missing. In the original task the table is read from a CSV file; here the columns are passed in directly.

Write analyze_housing(data, x_new) that returns a list of four results:

  1. Tax summary. For houses with exactly 2 bathrooms and 4 bedrooms, the [mean, std, median, min, max] of Tax, ignoring missing Tax. Use the sample standard deviation (ddof = 1).
  2. Large houses. Every row with Space > 800 (a missing Space does not qualify), each as a list of its nine values in the column order above with None for missing values, sorted by Price from highest to lowest. Rows with equal Price keep their input order.
  3. High-lot count. The number of houses whose Lot is at least the 80th percentile of the non-missing Lot values, where the percentile uses linear interpolation (sort the $m$ values and interpolate at 0-based position $0.8(m-1)$, the numpy and pandas default).
  4. Regression. Drop every row that has any missing value, fit an ordinary least-squares regression of Price on the 8 other columns with an intercept, and return [intercept, b_Bedroom, b_Space, b_Room, b_Lot, b_Tax, b_Bathroom, b_Garage, b_Condition, prediction], where prediction is the fitted price for the feature vector x_new (given in the order Bedroom, Space, Room, Lot, Tax, Bathroom, Garage, Condition).
def analyze_housing(data: dict[str, list], x_new: list[float]) -> list:
    ...

Constraints

  • data maps each of the nine column names to a list of the same length $n$, with $15 \le n \le 50$.
  • At least two houses with 2 bathrooms and 4 bedrooms have a known Tax.
  • The rows with no missing value give a design matrix (with intercept) of full column rank.
  • Numbers are compared with a relative or absolute tolerance of $10^{-6}$; integers may be returned as floats.

Example 1

Input: the 17 rows below, as columns, and x_new = [3, 1500, 8, 40, 1000, 2, 1, 0].

Price Bedroom Space Room Lot  Tax  Bathroom Garage Condition
 53     2      967   5   39   652     1       0       0
 55     2      815   5   33  1000     1       2       1
 56     3      900   5   35   897     1       1       0
 58     3     1007   6   24   964     2       2       0
 64     3     1100   7   50  1099     1       1       1
 44     4      897   7   25   960     2       1       0
 49     5     1400   8   30   678     1       1       1
 70     3     2261   6   29  2700     1       0       1
 72     4     1290   8   33   800     2       1       0
 82     4     1251   8   30  None    2       2       0
 70     4     1600   9   42  1300     2       2       0
 60     3      750   6   30   870     1       1       0
 66     5     1300   8  None 1100     2       2       1
 61     3      980   6   28  1000     2       0       0
 47     2      700   5   22   550     1       0       1
 90     4     1950   9   60  1450     3       2       1
 52     3      640   5   27   720     1       1       0

Output (rounded for display):

  • Tax summary: [1020.0, 255.34, 960.0, 800.0, 1300.0] (the qualifying taxes are 960, 800 and 1300; the house with missing Tax is ignored).
  • Large houses: 14 rows with prices 90, 82, 72, 70, 70, 66, 64, 61, 58, 56, 55, 53, 49, 44; the two 70s appear in input order (Space 2261 before Space 1600).
  • High-lot count: 4 (16 known lots, the percentile sits at position 12 of the sorted list, value 39).
  • Regression: [27.0303, -3.9889, 0.0104, 1.3923, 0.4495, 0.0029, 4.7014, 0.9286, -3.0418, 73.0102], fitted on the 15 complete rows.
Show hint

Which pandas operations already skip missing values for you, and which comparisons quietly treat a missing value as not matching?

Relevant roles: Data Scientist, Forward Deployed Engineer and Applied Scientist.

Related free problems