A code is a clue, not a diagnosis
A stored code names a circuit and a symptom the car has noticed. It does not name the broken part. A code for a lean mixture can be a split hose, a tired sensor, a leaking injector or a blocked filter, and only one of those is worth buying.
This is why lights come back. If the named sensor is replaced without testing, the actual fault is still there and the car logs the same code again within a week.

