[SciPy-User] Loading a CSV with loadtxt

Skipper Seabold jsseabold@gmail....
Wed Oct 27 14:31:59 CDT 2010

On Wed, Oct 27, 2010 at 3:19 PM, Athanasios Anastasiou
<athanastasiou@gmail.com> wrote:
> Hello everyone
> I have a CSV file with the following format:
> Unicode<100, Unicode<100, float, float, uint
> and i am trying to read it into a numpy array using:
> theData = numpy.loadtxt('primData.csv',delimiter=',',skiprows=1,dtype={'names':('NodeS','NodeT','flowF','flowB','ID'),'formats':('U100','U100','f','f','uint')})
> This fails with "expected a readable buffer object". I have also tried
> first opening the file through codecs as a utf-8 file and passing the
> file object into loadtxt but i still get the same error. And i have
> also tried defining the dtype outside of loadtxt and making sure that
> it works before using it any further.
> However, when i tried the code that is available at the cookbook:
> (with some minor modifications)
> http://www.scipy.org/Cookbook/InputOutput#head-b0366eac0be19c3d7c32fc81c47a7c02508b6f52
> It works exactly as expected.
> I don't mind using the latter but i am just wondering what it is that
> i am doing wrong with loadtxt(?)
> Any ideas why loadtxt fails in this way?

Hmm, I don't see what could be wrong.  What numpy version?  Can you
post some data as an attachment or using StringIO.StringIO that
replicates the error?

You might also try

theData = numpy.loadtxt('primData.csv', delimiter=',', skiprows=1,dtype=None)

to narrow down where the error is coming from.


More information about the SciPy-User mailing list