AnalystPath

Three-Flower Bouquet Costs

PandasMediumMid level~10 min

Problem

You are given a DataFrame `stems` with columns `stem_name` and `price`, the per-stem price for each kind of flower a florist stocks.

A signature bouquet uses exactly **three different stems**. List the cost of every possible three-stem bouquet. Within each bouquet the stem names must appear in alphabetical order, separated by commas, and no stem may repeat. Output `bouquet` (the comma-joined names) and `total_price` (the rounded sum of the three prices, to 2 decimals). Order by `total_price` descending, then `bouquet` ascending.

Input data

Example rows — the live problem includes the full dataset.

stems
stem_nameprice
Rose1.20
Tulip0.80
Lily1.50
Daisy0.40

Expected output

Your answer should return 4 rows with the columns bouquet, total_price.

Starter code (Pandas (Python))

import pandas as pd

def three_flower_bouquet_costs(stems) -> pd.DataFrame:
    # Your code here
    return stems

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