Forum Archive

Converting "*.dat" to array...

iBayern

Converting "*.dat" to array...

I have imported "banana.dat" data file to pythonista... i want to convert it to array using following code...

from numpy import *
DataIn = loadtxt('banana.dat')

But, I got error...I don not know what is the problem.

Webmaster4o

What's the error?

iBayern

Could not convert string to float: @relation

Webmaster4o

Copy the full stack, please. Are you on the beta, or on 2.0

iBayern

@Webmaster4o said:

stack

Thank you for your quick answers.

The header is:
@relation banana
@attribute At1 real[-3.09,2.81]
@attribute At2 real[-2.39,3.19]
@attribute Class {-1.0,1.0}
@inputs At1, At2
@outputs Class
@data
1.14,-0.114,-1.0
-1.52,-1.15,1.0
-1.05,0.72,-1.0
-0.916,0.397,1.0
-1.09,0.437,1.0
-0.584,0.0937,1.0
1.83,0.452,-1.0
-1.25,-0.286,1.0
1.7,1.21,1.0
-0.482,-0.485,1.0
1.79,-0.459,-1.0

I'm using the version 2.0...Maybe the problem is the header...how can I remove the deader?

omz

You can ignore the lines starting with @ by passing a comments argument to loadtxt. You also need to specify the delimiter, which is a comma in your case, but whitespace by default. This should work:

from numpy import *
data = loadtxt('banana.dat', comments='@', delimiter=',')
iBayern

@omz

Thank you very much indeed...it works.

Webmaster4o

Of course, my most sarcastic answer would be this

Phuket2

@Webmaster4o LOL...you have too much time on your hands

iBayern

:) usually I do use your sarcastic way:D This time, I just wanted to find the answer more qickly.