0

I'm trying to read values from a CSV file, but I'm getting an error.

Here is code snippet:

import numpy as np

file_read=np.loadtxt('stock_px.csv', delimiter=',')
print ("Restored data: \n" + str(file_read))

Here is error message:

  ValueError: could not convert string to float: 
2

1 Answer 1

1

Look up the documentation for np.loadtxt and type help(np.loadtxt) into your interpreter.

It has an optional dtype argument which is the data type that it tries to turn the data into. By default this is float. There are strings in your csv which np.loadtxt is unable to interpret as floats. If it's all strings you can set dtype=str instead.

Sign up to request clarification or add additional context in comments.

Comments

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.