You can often save the frame by cutting out the rotted wood and filling it with epoxy filler or a wood repair compound, which hardens and can be sanded and painted to match. The key is getting all the soft, damaged material out first - use a chisel or screwdriver to probe and remove anything that's genuinely rotted - then let the area dry completely before applying filler. If the rot goes deep into the structural parts of the frame or if more than about a third of the frame is affected, replacement becomes more practical and cost-effective. For future prevention, make sure water drains properly from the sill and consider caulking any gaps where moisture can get in.