Problem trying to build my own sklean transformer
The definition of dic should happen inside the fit method; you're wanting the rates to be based on the dataframe passed to fit.  So you'll want to set dic as another class attribute, to be referenced in the transform method.

(This kind of replacement is called target encoding, and there's an existing package to do it in sklearn.)