-2

I have a dataset like the one shown below

https://i.sstatic.net/1uxCK.png

I am able to read them into an numpy array but the datatype is of type string when it has read from the CSV file. I am unable to convert the same into float since without that i would not be able to proceed further.Mind you there are blank spaces between the two data columns shown in the first screenshot.

The numpy array structure when printed looks like in the screenshot given below:

https://i.sstatic.net/JFfzw.png

Note: (Observe the Single Quotation Marks between the start and end of each data line in the screenshot which is a proof that numpy has stored the data as a string rather than float)

Any help would be appreciated in helping me convert the data from string to float type?????? have Tried many things but yet all in vain!!!!!!!!

4
  • 2
    What code did you use to import your csv file? Commented Sep 17, 2014 at 12:38
  • 1
    possible duplicate of Numpy import from CSV and convert columns to float Commented Sep 17, 2014 at 12:41
  • 2
    @AKKI try np.loadtxt(filename) Commented Sep 17, 2014 at 12:42
  • @Lanting Thanks for redirecting me to the other discussion.That helped a lot and saved me a lot of time. The actual problem was the csv file I was reading was using tab as a delimiter rather than coma as delimiter. Hence when it found a empty field the script was not able to covert it into a float as it does not know how to do so.The root of the problem was the csv file not my code nor numpy's abilities.Your help was much appreciated Commented Sep 17, 2014 at 18:04

1 Answer 1

1

numpy.loadtxt(filename) should work out of the box: it yields numbers.

2
  • @EOL- does it just only store numbers only. does it remove all the header column names and stuff???? Commented Sep 17, 2014 at 16:49
  • 1
    @AKKI Use the documented parameter skiprows to do that. Commented Sep 17, 2014 at 18:46

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.