im scraping data from a website, all is going very well, except when a pulled result is equal to '?' or 'N/A' instead of a 'string' number which i convert to a float or int.
basically some values pulled dont have a value yet and on the website those missing values are replaced with '?' or 'N/A'.
ive also tried filtering these rows that contain these non float values to no avail, grrr! ive tried using df.replace, df. fillna etc and cant quite work out the fix. any help or workarounds would be greatly appreciated!!!
below is the error code:
> ValueError Traceback (most recent call last) <ipython-input-5-4c34bd6bd6c6> in <module>()
> 34 df2 = df.convert_dtypes()
> 35 df2['Price($)'] = df2['Price($)'].astype(float).round(3)
> ---> 36 df2['Change 1H(%)'] = df2['Change 1H(%)'].astype(float).round(2)
> 37 df2['Change 24H(%)'] = df2['Change 24H(%)'].astype(float).round(2)
> 38 df2['Change 7D(%)'] = df2['Change 7D(%)'].astype(float).round(2)
>
> 6 frames
> /usr/local/lib/python3.7/dist-packages/pandas/core/arrays/string_.py
> in astype(self, dtype, copy)
> 442 mask = self.isna()
> 443 arr[mask] = 0
> --> 444 values = arr.astype(dtype)
> 445 values[mask] = np.nan
> 446 return values
>
> ValueError: could not convert string to float: '?'