You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In [87]: df2=pd.DataFrame([['a', 1], ['b', pd.NA]])
In [108]: df2Out[108]:
010a11b<NA>In [109]: df2.replace({0: 'a'}, np.nan)
/home/torstein/anaconda3/lib/python3.7/site-packages/pandas/core/missing.py:47: FutureWarning: elementwisecomparisonfailed; returningscalarinstead, butinthefuturewillperformelementwisecomparisonmask=arr==xOut[111]:
010a11b<NA>In [112]: df2.dtypesOut[112]:
0object1objectdtype: object# This works:In [121]: df2[0].replace('a', np.nan)
Out[121]:
0NaN1bName: 0, dtype: object# This also works:In [126]: pd.DataFrame([['a', 1], ['b', np.nan]]).replace({0: 'a'}, 'b')
Out[126]:
010b1.01bNaN
Problem description
There are multiple similar issues, but in this case, there are no NaNs in the column specified by the replacement-dictionary. If the dataframe is created without additional column 1 with a pd.NA, even though no replacement is performed on that column, then replace works.
The text was updated successfully, but these errors were encountered:
tsoernes
changed the title
DataFrame.replace fails to replace value when columns are specified
DataFrame.replace fails to replace value when columns are specified and non-replacement columns contain pd.NA
Mar 19, 2020
@jorisvandenbossche
The underlying cause might be the same, but contrary to those issues, there
are no missing values in the column where values are to be replaced.
tsoernes
changed the title
DataFrame.replace fails to replace value when columns are specified and non-replacement columns contain pd.NA
DataFrame.replace fails to replace value when columns are specified and only non-replacement columns contain pd.NA
Mar 20, 2020
Code Sample, a copy-pastable example if possible
Problem description
There are multiple similar issues, but in this case, there are no NaNs in the column specified by the replacement-dictionary. If the dataframe is created without additional column
1
with apd.NA
, even though no replacement is performed on that column, then replace works.Expected Output
'a' to be replaced with nan
Output of
pd.show_versions()
The text was updated successfully, but these errors were encountered: