0

I need to convert the datatype of y_test from object to float64. I first converted into an array of strings ( In[54] ) and then to an array of floating point numbers (Inputs [83] & [85]) but it is not added to the y_test data frame.

y_test feature CO(ppm) is still displayed as object datatype ( Out[90] ).

Can someone please help me understand how to accomplish this? Thank you.

enter image description here

4
  • 1
    A few changes here would be helpful: 1) please post code as text rather than as an image; 2) for this question you could post a dataset of just a couple of entries which would illustrate your problem, and then we could run that ourselves which would help in understanding what's going on. It's definitely best to aim for a MRE whenever possible. Commented Oct 16, 2020 at 1:03
  • Please provide us with example input and desired output Commented Oct 16, 2020 at 1:15
  • All those Out lines just show a new array generated by the action. Nothing is being changed in-place. y_test remains unchanged. Commented Oct 16, 2020 at 1:39
  • That makes sense. I will post better framed questions next time. Thank you for your comments everyone. Commented Oct 16, 2020 at 14:28

1 Answer 1

1

Try:

y_test['CO'] = y_test.CO.apply(lambda x: x.replace(',','')).astype(float)
Sign up to request clarification or add additional context in comments.

1 Comment

Got it. String to float conversion also replaces the comma values. Thanks.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.