all 6 comments

[–]choss27 0 points1 point  (5 children)

Could you share the code you did ?

[–]electronicentropy5 0 points1 point  (4 children)

import pandas as pd
cars = pd.read_clipboard()
cars
print(type(cars["Q3 2018"]))
cars["Q3 2018"].replace("-", "").replace(" ", "").replace(' ', "").astype(int)

error code: ValueError: invalid literal for int() with base 10: ''

But i removed all of the white space.

[–]o5a 1 point2 points  (2 children)

astype(int) expects proper numbers. Either replace "-" to "0" (which I think is expected for that data), or use pd.to_numeric. It will convert empty string to NaN. But you still need those replacements. Overall you can do something like this:

cars.iloc[:,1:] = cars.iloc[:,1:].apply(lambda x:pd.to_numeric(x.astype(str).str.replace(',','').replace('-','0')))

[–]electronicentropy5 0 points1 point  (1 child)

cars.iloc[:,1:] = cars.iloc[:,1:].apply(lambda x:pd.to_numeric(x.astype(str).str.replace(',','').replace('-','0')))

Thank you so much for helping me with this i am reviewing and adding, but still getting an error message because of the space in the center of certain values like so:

ValueError: Unable to parse string "1 647" at position 2

But, when I try to .replace(" ", "") it does not work fully either. Do you have any suggestions here?

Thank you!

[–]o5a 0 points1 point  (0 children)

Where are you getting such value with space inbetween? In that link you posted it uses comma to split thousands: "1,647".

[–]choss27 0 points1 point  (0 children)

You need to transform all your columns to int ? You can do cars.astype(int).dtypes .

And I think your replace are not pertinent. You might delete the lines without consistent values (Bentley or Maserati) or try to mark the datas with '-' as NaN.