BUG: DataFrame.replace is broken in 0.12-dev · Issue #4115 · pandas-dev/pandas (original) (raw)
the DataFrame.replace
seems to be broken in 0.12 development version
this code:
df = pd.DataFrame({'Type':['Q','T','Q','Q','T'], 'tmp':2})
print df
print df.replace({'Type': {'Q': 0, 'T': 1}})
Return correct result in 0.11.0:
Type tmp
0 Q 2
1 T 2
2 Q 2
3 Q 2
4 T 2
5 T 2
Type tmp
0 0 2
1 1 2
2 0 2
3 0 2
4 1 2
5 1 2
and in 0.12.0.dev-795004d it does not work:
Type tmp
0 Q 2
1 T 2
2 Q 2
3 Q 2
4 T 2
5 T 2
Type tmp
0 0 2
1 1 2
2 0 2
3 1 2
4 0 2
5 1 2
Series.replace it works well, so the workaround for this bug is the following:
df['Type'] = df['Type'].replace({'Q': 0, 'T': 1})