Knowledge base / Python
pandas idxmin: lowest quotes, labels and missing values
Using synthetic shipping quotes, I explain a minimum label and why an unavailable quote should not win a comparison as zero.

The cheapest known quote and the best carrier are different questions. idxmin() can identify the label of the smallest number, but it does not assess reliability, service conditions or completeness of the price list. I start with that distinction so a technically correct answer does not acquire an unjustified meaning in a report. This example uses synthetic quotes for shipping the same parcel and targets pandas 3.1.1.
From three quotes to one label
Suppose three fictional companies quote 12, 9 and 9 units for the same service. Establish a shared unit and fee coverage before comparing them. If an amount concerns a different parcel or excludes part of the cost, choosing the smallest number can mislead. The library cannot resolve those definitions on the analyst’s behalf.
import pandas as pd
quotes = pd.Series([12, 9, 9], index=["alpha", "beta", "gamma"])
carrier = quotes.idxmin()
The result is the label "beta". Series.idxmin selects the first occurrence of a minimum. The amount is 9 and its first zero-based position is 1. These answers are not interchangeable. Series.min provides the value, while Series.argmin provides the position.
A complete report should show that beta and gamma share the lowest cost. Series order settles the method’s result, but it is not a substantive reason to prefer one carrier. If the report requires one supplier, add an explicit tie-breaking rule. If it requires the group of cheapest quotes, retain both observations rather than accidentally hiding one of them.
Do not treat different routes as the same quote
For a table, establish the orientation first. Each row represents a route and each column a carrier. Every cell holds a synthetic cost for the same parcel on the specified route:
costs = pd.DataFrame(
{"A": [12, 9, 11], "B": [8, 10, 11]},
index=["route1", "route2", "route3"],
)
cheapest_route = costs.idxmin(axis=0)
cheapest_carrier = costs.idxmin(axis=1)
cheapest_route maps A to route2 and B to route1: the lowest quote in each column. cheapest_carrier maps route1 to B, route2 to A and route3 to A because the tied minimum occurs there first. For a question about which carrier to choose on a particular route, you need the second direction. The first calculation answers a different question.
DataFrame.idxmin returns a Series: one answer per column with axis=0 or per row with axis=1. The old presentation as a one-row table obscured that distinction. Here, I describe the mappings without reproducing a printed dtype line. Representation details for text labels are not the central information needed to understand the example.
An absent quote is different from a zero cost
Replace the middle quote with a missing value. Beta’s cost is now unknown. Default NA exclusion lets you select the cheapest quote among those you actually have:
incomplete = pd.Series([12, None, 9], index=["alpha", "beta", "gamma"])
known_carrier = incomplete.idxmin()
known_carrier identifies gamma. The report should explain that the price list is incomplete. There is no evidence that gamma also beats beta’s unknown quote. I would not fill the missing value with zero: that invents a free service and selects it as the minimum. This small decision illustrates how correct function use depends on the meaning of data.
In pandas 3.1.1, incomplete.idxmin(skipna=False) raises ValueError. One missing observation is sufficient; the whole Series need not be NA. An all-missing Series also raises with the default skipna=True, and an empty Series has no minimum to identify. The pandas 3.0 release notes describe the changed behavior. The old statements promising a NaN result are outdated.

Separate result availability from the carrier label
If comparing incomplete quotes is permitted, establish whether at least one known amount exists. dropna removes missing observations while preserving remaining labels by default:
available = incomplete.dropna()
result = {"available": not available.empty, "carrier": None}
if result["available"]:
result["carrier"] = available.idxmin()
Here the result is available and the carrier is gamma. With no quotes remaining, availability is false and carrier stays None. This is a convention in the surrounding code, rather than a special idxmin response. A separate availability field tells recipients whether a selection took place, instead of requiring them to infer that from an empty-looking label in a report.
For a DataFrame, make the corresponding decision for the direction being analyzed. A route with no quotes should not be assigned a carrier from all-NA data. You can set it aside in a separate missing-data list. numeric_only=True restricts included types to numeric and boolean data, but it neither supplies absent quotes nor fixes incompatible units. Select appropriate cost columns first.
Check meaning before publishing the answer
Minimum temperature, shortest duration and lowest sales describe different situations. Lowest sales do not indicate the best product, and a small value alone does not establish an anomaly. This exercise minimizes comparable quoted cost only; other criteria remain outside its scope. State that boundary before someone treats an automatically selected label as the winner of the whole business process.
For an exercise, add a delta quote of 7 and identify the changes to the minimum’s label, value and position. Next, suppose two companies share the same index identifier. Consider whether the label alone can identify one quote. For selecting the highest value, see the separate pandas idxmax entry. Define the compared observations and the meaning of the result before choosing the method.
Key takeaways
Does idxmin return an amount or a supplier?
It returns the first minimum’s label. Here the label identifies a supplier; min gives the amount and argmin gives a position.
Does skipna=False with one missing value return NaN?
In pandas 3.1.1 it raises ValueError. An all-NA Series also raises with skipna=True.
Does the lowest cost mean the best quote?
The method compares numbers only. Establish matching services, units and fees first; other criteria need separate assessment.
AI was used in an automated way while working on this article. If you want to learn how to do it too, check out this project.
