Soil Moisture Classification per Greenhouse
Problem
You are given two DataFrames.
`greenhouse` has columns `house_id` and `house_name`; each row names one greenhouse.
`moisturelog` has columns `house_id`, `moisture_pct`, and `reading_day`; each row is the soil moisture percentage recorded in a greenhouse on a given day.
For every greenhouse, compute the **average moisture** of its readings taken during **March 2021** (from `2021-03-01` to `2021-03-31` inclusive) and classify it under a new column `moisture_label`:
- `'Dry'` when the average moisture is **30 or below**,
- `'Soaked'` when the average moisture is **60 or above**,
- `'Balanced'` for everything in between.
Return the columns `house_name` and `moisture_label`. Rows may be in any order. Only greenhouses with at least one March reading appear.
Input data
Example rows — the live problem includes the full dataset.
| house_id | house_name |
|---|---|
| 1 | Fern Wing |
| 2 | Orchid Bay |
| 3 | Cactus Row |
| house_id | moisture_pct | reading_day |
|---|---|---|
| 1 | 20 | 2021-03-04 |
| 1 | 28 | 2021-03-18 |
| 2 | 45 | 2021-03-09 |
| 2 | 55 | 2021-03-22 |
| 3 | 70 | 2021-03-11 |
Expected output
Your answer should return 3 rows with the columns house_name, moisture_label.
Starter code (Pandas (Python))
import pandas as pd
def soil_moisture_classification(greenhouse, moisturelog) -> pd.DataFrame:
# Your code here
return greenhouseSolve this Pandas question free
Write Pandas (Python) and run it instantly in your browser — even on your phone. No signup needed to try.
Solution & explanation
Create a free account to unlock the optimal solution, a step-by-step explanation, and the hidden test cases that grade your answer.
Sign up free to unlock