unai abrisketa sanchez
unai abrisketa sanchez

Reputation: 386

Troubles using astype in a dataframe

I am trying to convert my dataset input matrix marked as X to the type float. I have some columns which has the thousands divided by '.' and the decimals too.

When I enter de command:

X=X.astype(float)

I get the error that tells me that it is impossible to convert string to float. I have try to include the thousands and decimal field when I import the dataset but I am not sure how to use it, could anyone help me?

Upvotes: 0

Views: 57

Answers (1)

Eren Han
Eren Han

Reputation: 321

In order to bypass the errors in the column which is mixed type, I'm using the method in below.

x=pd.to_numeric(x, errors='coerce')

Upvotes: 1

Related Questions