Open JulianKlug opened 2 years ago
Gist with more complete example: https://gist.github.com/JulianKlug/065c7f9918b5e5551e78b39e72375282
For everyone simply looking the solution for this issue, it can be prevented by converting to string first, and then converting back to float, or only converting elements of type str
.
df['value'] = df['value'].astype(str).str.replace("'", "").astype(float)
# OR
df['value'] = df['value'].apply(lambda x: x.replace("'",'') if type(x) is str else x)
Hey @JulianKlug could I please try working on this fix?
@nik1097 : Sure! Although I am not part of the maintainers, any PR is welcome and we can then discuss the proposal from there
Pandas version checks
[x] I have checked that this issue has not already been reported.
[X] I have confirmed this bug exists on the latest version of pandas.
[X] I have confirmed this bug exists on the main branch of pandas.
Reproducible Example
Issue Description
When replacing a string in a column with mixed data, this replaces all non-string data with NaN without a warning (silent failure).
See also: https://stackoverflow.com/q/43187436/3903778
Expected Behavior
Expected behaviour would either be an error or a warning, as this is the case when applying str.replace to data of non-string type (see example below).
Fails with:
AttributeError: Can only use .str accessor with string values!
Installed Versions