I have a dataframe and one column Quantity has the below values
Col1
20,000
20
-10,000
-50
I want to convert this column to a float, as later I am doing a comparison with a floating number to filter some rows. However I get some or the other error: "Can only use .str accessor with string values!"
I think I found the issue, when it reads the value "-50", it reads it as a float, so no "str" accessor is valid. While loading the csv file the column is an object type series
my code looks like
df['Qty'] = np.where(~df['Qty'].str.contains(','),df['Qty'],df['Qty'].str.replace(",",""))
df['Qty'] = df['Qty'].astype(float)
How can I resolve this issue?
pd.to_numericpd.to_numeric(series, errors='coerce')