开发者

Numpy.genfromtxt method works in windows but not Linux

I am doing some data crunching and I have built a program开发者_运维知识库 for Python in Windows and now I want to run it on my Linux box so it can crunch while I go home to drink beer, etc.

One piece of the code (an important one) ingests some columnar values from a CSV file via Numpy's genfromtxt method. the snippet of code in question is:

rfd_values = np.genfromtxt(file_in, delimiter=',',
             skip_header=1,
             invalid_raise=0,
             usecols = cols)

So the idea here is, skip the header, the delimiter is a comma, and give me only the columns from the list callled cols. This works just hunky-dorey on my Windows laptop (same version of Python and Numpy, 2.6 and 1.5 respectively), but when I run it in Linux it tells me:

*TypeError: genfromtxt() got an unexpected keyword argument 'skip_header'*

I tried putting everything on one line, and changing the quotes around the delimiter keyword, but that didn't seem to work. Its probably something silly, but I can't seem to put my finger on it. I looked through a bunch of forums and the Numpy docs and didn't see anything that sounded close to what I was seeing. I am wondering what it is that I am missing.

I would greatly appreciate any insight.

Thanks in advance!

-Jeff


You said you're actually using version 1.3 on Linux. That one has an argument skiprows which is the same as skip_header. Considering numpy.genfromtxt isn't even in documentation for 1.3, I would guess it was just being tested in 1.3, and the final signature wasn't quite set. That being said, there is a workaround for your case. You can use the names=True keyword parameter, instead. In that case, the first row will be used not for data, but to determine the column names (which you can then use, instead of column numbers in the list passed as usecols).

But there's another problem. The invalid_raise argument isn't in 1.3 either.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜