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
Pandas will raise the error ValueError: could not convert string to float: '16.5%' despite the fact that the errors='ignore' parameter was passed in. This is probable due to the implementation of astype, as can be seen in pandas.core.generic.py lines 5658 - 5680
ifis_dict_like(dtype):
ifself.ndim==1: # i.e. Seriesiflen(dtype) >1orself.namenotindtype:
raiseKeyError('Only the Series name can be used for ''the key in Series dtype mappings.')
new_type=dtype[self.name]
returnself.astype(new_type, copy, errors, **kwargs)
elifself.ndim>2:
raiseNotImplementedError(
'astype() only accepts a dtype arg of type dict when ''invoked on Series and DataFrames. A single dtype must be ''specified when invoked on a Panel.'
)
forcol_nameindtype.keys():
ifcol_namenotinself:
raiseKeyError('Only a column name can be used for the ''key in a dtype mappings argument.')
results= []
forcol_name, colinself.iteritems():
ifcol_nameindtype:
results.append(col.astype(dtype[col_name], copy=copy))
else:
results.append(results.append(col.copy() ifcopyelsecol))
Expected Output
One would expect the pd.DataFrame to successfully type cast, leaving the col_b as an np.object type
The text was updated successfully, but these errors were encountered:
…ck for the absense of the exception we'd normally throw. Assert the resulting dataframe against a reference dataframe. Move the test case to test_dtypes.
Code Sample, a copy-pastable example if possible
Given the code sample below:
Problem description
Pandas will raise the error
ValueError: could not convert string to float: '16.5%'
despite the fact that theerrors='ignore'
parameter was passed in. This is probable due to the implementation ofastype
, as can be seen inpandas.core.generic.py
lines 5658 - 5680Expected Output
One would expect the
pd.DataFrame
to successfully type cast, leaving thecol_b
as annp.object
typeThe text was updated successfully, but these errors were encountered: