No, this won't work
First Pandas takes keys and values from your dictionary and then calls replace with these iterables:
keys, values = zip(*items)
to_replace, value = keys, values
return self.replace(to_replace, value, inplace=inplace,
limit=limit, regex=regex)
Next, since you now have list_like keys and values, it feeds into replace_list:
elif is_list_like(to_replace): # [NA, ''] -> [0, 'missing']
if is_list_like(value):
new_data = self._data.replace_list(src_list=to_replace, dest_list=value,
inplace=inplace, regex=regex)
Next, replace_list attempts to perform a comparison between an array of tuples and an array of values:
def comp(s):
if isnull(s):
return isnull(values)
return _possibly_compare(values, getattr(s, 'asm8', s),
operator.eq)
masks = [comp(s) for i, s in enumerate(src_list)]
Finally, _possibly_compare checks if the values consist of scalars while the keys are array-like, causing an error:
if is_scalar(result) and (is_a_array or is_b_array):
raise TypeError("Cannot compare types %r and %r" % tuple(type_names))
There are bits, possibly important bits, I've excluded here. But hopefully you get the gist.
Conclusion
In my opinion, pd.Series.replace has serious problems. Unlike most of the Pandas API, it is often unpredictable, both in what it achieves and in performance. It's also clear blocks of it are written in pure Python and do not perform well.
The documentation sums up the ambiguity well:
This method has a lot of options. You are encouraged to experiment and
play with this method to gain intuition about how it works.
pd.Series.map is efficient and doesn't suffer from the pure Python logic implemented in replace.
See Replace values in a pandas series via dictionary efficiently for another example.
Stick with map and don't look back to replace.