AnalystPath

Soil Moisture Classification per Greenhouse

PandasEasyJunior level~10 min

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.

greenhouse
house_idhouse_name
1Fern Wing
2Orchid Bay
3Cactus Row
moisturelog
house_idmoisture_pctreading_day
1202021-03-04
1282021-03-18
2452021-03-09
2552021-03-22
3702021-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 greenhouse

Solve 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

Related Pandas questions