【问题标题】:error in matplotlib library in python while using csv2rec使用 csv2rec 时 python 中的 matplotlib 库出错
【发布时间】:2011-11-23 20:09:45
【问题描述】:

我在 Ipython 中工作,试图加载一个 csv 文件。

from matplotlib import *
data=matplotlib.mlab.csv2rec('helix.csv',delimiter='\t')

这是错误信息

IOError                                   Traceback (most recent call last)
/mnt/hgfs/docs/python/<ipython console> in <module>()
/usr/lib/pymodules/python2.7/matplotlib/mlab.pyc in csv2rec(fname, comments, skiprows, checkrows, delimiter, converterd, names, missing, missingd, use_mrecords)
   2125 
   2126     # reset the reader and start over
-> 2127     fh.seek(0)
   2128     reader = csv.reader(fh, delimiter=delimiter)
   2129     process_skiprows(reader)      
IOError: [Errno 29] Illegal seek

是否有人已经运行此错误?我尝试重新安装所有东西,我正在使用 Python2.7,并且我有 Matplotlib v0.99.3、Numpy v1.5.1、Ipython0.10.1

【问题讨论】:

  • 我仍然没有找到这个问题的答案,但是要读取我的 csv 文件,我正在使用另一个命令行:'from numpy import *''ld=numpy.genfromtxt('file.csv' ,names=True,dtype=None,delimiter='\t')'
  • 文件肯定有问题,你应该提供给别人帮忙。
  • 我尝试使用我创建的一个简单文件(2 列,2 行带数字),但它也不起作用,所以我不确定问题出在文件中。
  • 好的,请提供创建该简单文件的代码。
  • 我没有使用任何代码,我去了Excel,将第一行命名为“markers”,其他3行:line1、line2和line3;对于这些列,我将它们命名为 snp1、snp2、snp3,对于 line1,我将 A、A、A line2 命名为 A、B、A,而 line3 命名为 B、B、B。然后我只是将文件保存为 file.csv

标签: python csv numpy matplotlib ipython


【解决方案1】:

我试过这个文件:

snp1,snp2,snp3
A,A,A
A,B,A
B,B,B

结果如下:

In [3]: csv2rec('helix.csv')
Out[3]: 
rec.array([('A', 'A', 'A'), ('A', 'B', 'A'), ('B', 'B', 'B')], 
      dtype=[('snp1', '|S1'), ('snp2', '|S1'), ('snp3', '|S1')])

我有 matplotlib 1.0.1,所以你可以尝试更新它,我无法访问旧的 matplotlib 进行测试。

【讨论】:

  • 所以你刚刚升级了matplotlib?
猜你喜欢
  • 2015-12-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-02-07
  • 1970-01-01
  • 2016-02-18
  • 2018-09-07
  • 1970-01-01
相关资源
最近更新 更多