读取数据文件的简单方法
DataFile的Python项目详细描述
此包提供了打开数据文件的简单方法 通过返回对应于 如果列包含字符串,则返回字符串数组。
默认情况下,它将尝试从注释中猜测索引,如果失败,则将索引它。 从0到n:
#!/usr/bin/env python from datafile.extractfile import dataFile f = dataFile("./datafile/test/testdocfile.txt") # the index will be guessed and if not found it will # be indexed from 0 to n f = dataFile("./datafile/test/testdocfile.txt",index="auto") #f will be indexed from 0 to n #f["0"] will return a numpy array of the first column. #f["0",1] will return a numpy array of the index number 1 of the first column, # if the column is divided in index (ensemble of points separated by one or more space) f = dataFile("./datafile/test/testdocfile.txt" , "A B C D") #f will be indexed on "A" "B" "C" (if three columns) f = dataFile("./datafile/test/testdocfile.txt" , ["A", "B","C","D"] #f will be indexed on "A" "B" "C"
猜测
如果数据文件在注释中包含如下行: #长x(nm)y(nm)d(a) 文件在三列,它将索引这三列 使用“lx(nm)”“ly(nm)”,“d(a)”:
#!/usr/bin/env python f = dataFile("./file") f["Lx"] f["x"] #both are going to return the first column f["nm"] #will return a key error
主要用途
我将它与ipython一起用于绘制数据并探索它们。 发射伊普顿-Pylab将发射伊普顿 matplotlib已加载。 在用数据文件加载文件后,您可以打印数据 只有类型图(f[“a”]、f[“b”])