0

My csv file(K2CsSb DOS135.csv) is very simple like:

-7.21E+00   1.34E-01
-7.16E+00   1.15E-01
-7.13E+00   0.00E+00
-7.10E+00   0.00E+00
-7.07E+00   0.00E+00

And I use genfromtxt to import this file like:

dosdata = genfromtxt('K2CsSb DOS135.csv',delimiter=',')

if I print(dosdata),it shows me:

[[-7.21   0.134]
 [-7.16   0.115]
 [-7.13   0.   ]
 ..., 

I used this 2D array data for interp1d in numpy.

Everything looks perfect. The csv file was edited in MS excel in WINDOWS.

Right now I am using MAC OS X and use mac MS excel editing this file only cut-paste, no change the data type. Then when I import this file as same as before and print. The show me error: [-7.21 nan nan nan nan nan nan] f = interp1d(data[:,0], data[:,1]) IndexError: too many indices for array If I added dosdata = genfromtxt('K2CsSb DOS135.csv',delimiter=',',dtype=None) Looks is a tur like:

(-7.21, b'1.30E-01\r-7.16E+00', b'1.20E-01\r-7.13E+00', b'0.00E+00\r-7.10E+00', b'0.00E+00\r-7.07E+00')

why happen that and how to fix it?

rfeynman
  • 97
  • 1
  • 9
  • It is not clear to me if this will fix your problem, but since your file does not use a comma as a delimiter, don't use the argument `delimiter=','` in `genfromtxt`. – Warren Weckesser Aug 15 '15 at 12:04
  • add this **defaultfmt ="%f"** – dsgdfg Aug 15 '15 at 12:11
  • That MAC `\r` (CR) appears to be giving the DOS version problems. DOS uses (LF/CR), UNIX (LF). I'm a little surprised that `delimiter=','` works, since you don't have `,` in the file. – hpaulj Aug 15 '15 at 17:41

1 Answers1

0

Find a solution. In mac excel , using save as... has two type of csv. One is MS-DOS csv; another is Microsoft csv. Choose Microsoft csv could solve the problem.

rfeynman
  • 97
  • 1
  • 9