Refactor pandas.core.generic.NDFrame.to_replace() to appease static type analysis
Current implementation of `pandas.core.to_replace()` method won't allow type hints, as noted in #32542 . Contributor guidelines [suggest](https://pandas.pydata.org/pandas-docs/stable/development/contributing.html#style-guidelines) a refactor in this case.