Use df.set_index("id") to make a column the row labels. You can then look up a record with df.loc[label] on the resulting DataFrame. This keeps the original row order and allows duplicate labels by default. If you mainly export or join on the ID, a regular column is often simpler.
Look up a row by label or position
import pandas as pd
jobs = pd.DataFrame({
"job_id": ["R02", "R01"],
"minutes": [8, 14],
})
indexed = jobs.set_index("job_id")
assert indexed.loc["R01", "minutes"] == 14
assert indexed.iloc[0]["minutes"] == 8
assert list(indexed.index) == ["R02", "R01"]
.loc uses the row label. .iloc uses integer position. The first row is still R02 after setting the index. If you need sorted labels, ask for that with a separate operation. The example keeps jobs as the original table and assigns a new result to indexed.
By default, the chosen column is moved out of the ordinary columns. Use drop=False if a subsequent step needs that column as well. If the row labels should return to columns for export, call reset_index() and check for any name collision with columns already present. Use reset_index(drop=True) only when the existing labels can be discarded.
Check for missing and duplicate index labels
A job table may be expected to have one row per job ID. Validate that assumption before relying on a lookup to identify a single row. For example, reject rows with missing IDs or inspect whether the candidate column is unique. Multiple readings per sensor could instead need a composite key such as sensor ID plus recorded time. Check that the combination is unique under the expected data contract.
If the DataFrame contains duplicate index values, .loc for one label can return multiple rows. That can be exactly what you intend, but following code needs to handle it. A report that quietly accepts one arbitrary row can lose observations. Decide whether duplicate labels are valid, then make the result shape part of your test.
Understand alignment before combining objects
Pandas can align many operations by labels. If one Series contains amounts for job IDs R01 and R02, adding another Series indexed by the same IDs can pair the matching values even if they appear in different order. Missing labels may produce missing results. Check index labels before interpreting the output.
For example, the amount for R01 can align with another amount for R01 even if it appears second in one Series and first in the other. If you intend to pair rows by position, verify that both sources use the same order before converting to arrays. For an explicit merge, name the join keys and check the counts of missing and duplicate matches.
Keep export and import behavior visible
A DataFrame index can become an extra column when exporting a CSV. Decide whether that label is part of the output contract and pass the corresponding index option. If the row ID was moved exclusively into the index and you export with index=False, the ID will be absent. Set it back as a column first when the receiver needs it.
During import, identifier text can be parsed as a number unless you choose an appropriate type. An index made from numeric ID 42 no longer distinguishes it from an original label 0042. Preserve identifiers as strings at ingestion when the spelling matters. Reconcile a few original values against their labels after indexing.
Choose a simple default
When a DataFrame primarily flows through joins and file exports, keep the ID column explicit until there is a clear reason to change it. If you repeatedly look up records by a known unique key, a named index can make access easier to read. Test one missing ID, one duplicate ID, and one input with reversed row order to check that the chosen design matches the intended operation.