`Stop Sorting by Price: Normalize Supplier Quotes With pandas First

Procurement spreadsheets have a quiet bug. You paste three quotes into three rows, sort the price column, and the top row looks like the winner. But the rows are not measuring the same thing, so the sort is meaningless.

This post shows a small pandas pattern for fixing that. The example data is bulk henna powder quotes, because the problem is easy to see there, but the same approach works for any commodity where "same product" hides real differences: spices, tea, resins, packaging film.

All prices below are invented for the demo.

The problem in one table

Say four suppliers reply to your request for henna powder:

supplier price per kg shipping term pack batch document sifting stated
Mill A 4.10 FOB bulk bag no no
Mill B 4.60 CIF lined bag yes yes
Trader C 3.80 EXW plain bag no no
Mill D 4.35 FOB lined bag yes yes

Sort by price and Trader C wins. But EXW means you pay for everything after the factory gate, while CIF already includes freight and insurance to a named port. And two of the four rows have no batch document and no stated sifting, so you do not know what you would receive.

Two fixes are needed: put prices on a common shipping basis, and filter out rows that are missing required information before ranking anything.

Step 1: load the data

`python
import io
import pandas as pd

raw = """supplier,price_per_kg,incoterm,pack,batch_doc,sifting_stated
Mill A,4.10,FOB,bulk bag,no,no
Mill B,4.60,CIF,lined bag,yes,yes
Trader C,3.80,EXW,plain bag,no,no
Mill D,4.35,FOB,lined bag,yes,yes
"""
df = pd.read_csv(io.StringIO(raw))
`

In real use you would read a CSV that you fill in from each supplier's written reply. Keep one row per supplier, and one column per question you asked every supplier.

Step 2: bring prices to one shipping basis

Shipping terms split cost and risk at different points. To compare prices fairly you need an estimate of what each term leaves for you to pay. The numbers in this dict are placeholders. Replace them with real quotes from a freight forwarder for your route.

python
adder = {"EXW": 0.55, "FOB": 0.35, "CIF": 0.0}
df["adj_price"] = df["price_per_kg"] + df["incoterm"].map(adder)

A map call returns NaN for any term that is not in the dict, which is useful here. If a supplier writes a term you did not plan for, the adjusted price goes blank instead of silently pretending to be comparable.

Step 3: flag rows that are missing required answers

Decide which fields are non-negotiable, then mark each row as comparable only if every one of them is a clear "yes".

python
required = ["batch_doc", "sifting_stated"]
df["comparable"] = df[required].eq("yes").all(axis=1)

Anything other than "yes" counts as a miss, including blanks and typos, which is the safe direction to fail in.

Step 4: rank, but only among comparable rows

python
print(df.sort_values("adj_price")[["supplier", "adj_price", "comparable"]])
print(df[df["comparable"]].sort_values("adj_price")[["supplier", "adj_price"]])

Output from the run:

`plaintext
supplier adj_price comparable
2 Trader C 4.35 False
0 Mill A 4.45 False
1 Mill B 4.60 True
3 Mill D 4.70 True

supplier adj_price
1 Mill B 4.6
3 Mill D 4.7
`

Notice what happened. Trader C was the cheapest sticker price and is still the cheapest adjusted one, but it is not comparable, because the batch document and the sifting details are missing. Among the rows you can fairly compare, Mill B comes first.

Choosing the required fields

The field list is the part that takes domain knowledge. For botanical powders, a decent starting set is:

  • ingredient list (single ingredient or blend)
  • intended use
  • sifting or fineness, confirmed by a physical sample
  • moisture handling and stated shelf life
  • a batch-level analysis for the lot you will receive
  • complaint route

I modeled these on the kind of detail producers publish on their own pages. Kirpal Export Overseas, for instance, keeps a published producer FAQ, which is handy for seeing how a producer words these answers. Disclosure: the author's team works with that company.

Gotchas

Text fields drift. "Yes", "yes ", "Y" and "yes (on request)" are four different strings. Normalize with str.strip().str.lower() first, and decide up front what counts as a yes.

Currency and units. If one supplier quotes per pound or in another currency, convert before the adjustment step. Do not hide that conversion in a spreadsheet cell.

Samples beat columns. A column can say "sifted" and still describe a coarse powder. Keep a field for what you observed on a sample, and treat it as the tie-breaker.

Where to take it next

Add a lead_time_weeks column and weight it. Log the date of each quote, since prices move. Keep the CSV in version control, so you can see what changed between rounds.

None of this replaces judgment. It only stops the first sort from deciding the question before you have looked at what is being compared.`