我想知道如何用python编程方式索引/访问一些数据。 我有一组钻孔的柱状数据:深度,温度,梯度,伽马。有n个钻孔。我有一个标题,其中列出了钻孔名称和数字标识。例如:
Bore_name,Bore_ID,,,Bore_name,Bore_ID,,,, ...
<a row of headers>
depth,temp,gradient,gamma,depth,temp,gradient,gamma ...
我不知道如何索引数据,除了粗鲁的迭代:
^{pr2}$这种方式似乎很简单,但我最近一直在使用R,并且已经习惯了它们通过从头解释的类和子类引用数据对象的方式。在
如果你喜欢R数据表,有一些(至少)尝试通过NumPy核心中的附加类和外部Python库在NumPy中重新创建该功能。我发现最有希望的是费尔南多·佩雷斯的图书馆。下面是它的工作原理。在
实例化DataArray实例,方法是调用构造函数并传入一个普通的NumPy数组和一个元组列表,每个轴一个元组,由于ndim=2,列表中有两个元组,每个元组由axis label(str)和该轴的标签序列(list)组成。在
^{pr2}$以下是命名行和列的习惯用法:
另请参见namedtuple:
^{pr2}$datarray
(谢谢道格)当然更一般。在您可以将数据放入每个钻孔的
dict
,由钻孔id和值作为dicts,标题作为键。大致如下:使用这些方法,从文件中读取可能会有点麻烦,但是对于绘图,您可以做一些类似的事情
^{pr2}$相关问题 更多 >
编程相关推荐