Overview:
I have scrapped some data off a website, put into a Pandas DataFrame but for some reason, I can't seem to convert the Data Type from an Object to an Integer or Float (for the point of this, either is fine).
I have looked through a few posts which have thankfully helped me get here, but for some reason, everything I try doesn't seem to work
A sample of the Dataset:
Condition_Type State Price Year Make Model
In Stock SA $24,654 2017 Mazda 3
Used Car VIC $23,162 2016 Holden Trax
Used Car VIC $15,777 2011 Volkswagen Tiguan
Used Car VIC $12,634 2012 Volkswagen Polo
In Stock VIC $70,501 2017 Volkswagen Amarok
What I have attempted so far:
df["Price"] = df["Price"].str.replace("$","").astype(int)
ValueError: invalid literal for int() with base 10:
df["Price"] = df["Price"].astype(str).astype(int)
ValueError: invalid literal for int() with base 10:
pd.Series(df["Price"]).convert_objects(convert_numeric=True)
FutureWarning: convert_objects is deprecated. Use the data-type specific converters pd.to_datetime, pd.to_timedelta and pd.to_numeric.
pd.to_numeric(df["Price"], errors='coerce')
Returns NaN
pd.to_numeric(df["Price"], errors='ignore')
Values stay as objects
df["Price"] = df["Price"].astype(np.int64, inplace=True)
ValueError: invalid literal for int() with base 10:
This last one has worked in the past, but for some reason, it isn't working on this data-set.
Any ideas?
Thanks, Adrian