Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/heroku/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Pandas 将操作挂起_Pandas_Hdf5_Pytables_Pickle - Fatal编程技术网

Pandas 将操作挂起

Pandas 将操作挂起,pandas,hdf5,pytables,pickle,Pandas,Hdf5,Pytables,Pickle,我正在探索Python,特别是带有HDF5的Pandas,是否是进行时间序列建模的合适环境。。。结果是,我在这些方面几乎没有经验,所以请原谅我的愚蠢问题 直截了当地说,即使是在HDF5文件中插入最基本的虚拟数据,我也遇到了一些问题。我在中遵循提供的代码,但当我开始以storer格式编写代码时,代码执行挂起。我还没有尝试过表格格式,我想先让它工作。我正在运行以下文件 test\u put.py: from IPython.core.debugger import Tracer; debugStar

我正在探索Python,特别是带有HDF5的Pandas,是否是进行时间序列建模的合适环境。。。结果是,我在这些方面几乎没有经验,所以请原谅我的愚蠢问题

直截了当地说,即使是在HDF5文件中插入最基本的虚拟数据,我也遇到了一些问题。我在中遵循提供的代码,但当我开始以storer格式编写代码时,代码执行挂起。我还没有尝试过表格格式,我想先让它工作。我正在运行以下文件

test\u put.py:

from IPython.core.debugger import Tracer; debugStart = Tracer()
import pandas as pd
import numpy as np
import tables

print "Pandas version: " + pd.__version__ # 0.11.0
print "NumPy version: " + np.__version__ # 1.7.1
print "Tables version: " + tables.__version__ # 2.4.0

df = pd.DataFrame(np.random.randn(1000 * 1000, 100),
                  index=range(int(1000 * 1000)),
                  columns=['E%03d' % i for i in xrange(100)])

for x in range(20):
    df['String%03d' % x] = 'string%03d' % x

def test_storer_put():
    store = pd.HDFStore('test_put.h5','w')
    debugStart()
    store['df'] = df
    store.close()

def test_table_put():
    store = pd.HDFStore('test_put.h5','w')
    store.put('df',df,table=True)
    store.close()

test_storer_put()
在ipython中使用ipdb,我有一个到挂线的调用堆栈,如下所示。这一行调用cPickle,我假设它是某种编译库。我不能再深入这一行(使用“s”),所以我不知道问题出在哪里

  ~/test_put.py(20)test_storer_put()
     18     store = pd.HDFStore('test_put.h5','w')
     19     debugStart()
---> 20     store['df'] = df
     21     store.close()
     22

  ~/anaconda/lib/python2.7/site-packages/pandas/io/pytables.py(241)__setitem__()
    239
    240     def __setitem__(self, key, value):
--> 241         self.put(key, value)
    242
    243     def __delitem__(self, key):

  ~/anaconda/lib/python2.7/site-packages/pandas/io/pytables.py(536)put()
    534             table
    535         """
--> 536         self._write_to_group(key, value, table=table, append=append, **kwargs)
    537
    538     def remove(self, key, where=None, start=None, stop=None):

  ~/anaconda/lib/python2.7/site-packages/pandas/io/pytables.py(871)_write_to_group()
    869             raise ValueError('Compression not supported on non-table')
    870
--> 871         s.write(obj = value, append=append, complib=complib, **kwargs)
    872         if s.is_table and index:
    873             s.create_index(columns = index)

  ~/anaconda/lib/python2.7/site-packages/pandas/io/pytables.py(2005)write()
   2003             blk = data.blocks[i]
   2004             # I have no idea why, but writing values before items fixed #2299
-> 2005             self.write_array('block%d_values' % i, blk.values)
   2006             self.write_index('block%d_items' % i, blk.items)
   2007

  ~/anaconda/lib/python2.7/site-packages/pandas/io/pytables.py(1799)write_array()
   1797             vlarr = self._handle.createVLArray(self.group, key,
   1798                                               _tables().ObjectAtom())
-> 1799             vlarr.append(value)
   1800         elif value.dtype.type == np.datetime64:
   1801             self._handle.createArray(self.group, key, value.view('i8'))

  ~/anaconda/lib/python2.7/site-packages/tables/vlarray.py(462)append()
    460         atom = self.atom
    461         if not hasattr(atom, 'size'):  # it is a pseudo-atom
--> 462             sequence = atom.toarray(sequence)
    463             statom = atom.base
    464         else:

  ~/anaconda/lib/python2.7/site-packages/tables/atom.py(1000)toarray()
    998
    999     def toarray(self, object_):
-> 1000         buffer_ = self._tobuffer(object_)
   1001         array = numpy.ndarray( buffer=buffer_, dtype=self.base.dtype,
   1002                                shape=len(buffer_) )

> ~/anaconda/lib/python2.7/site-packages/tables/atom.py(1112)_tobuffer()
   1110
   1111     def _tobuffer(self, object_):
-> 1112         return cPickle.dumps(object_, cPickle.HIGHEST_PROTOCOL)
   1113
   1114     def fromarray(self, array):
挂线范围内的参数为:

ipdb> a
self = ObjectAtom()
object_ = [['string000' 'string001' 'string002' ..., 'string017' 'string018'
  'string019']
 ['string000' 'string001' 'string002' ..., 'string017' 'string018'
  'string019']
 ['string000' 'string001' 'string002' ..., 'string017' 'string018'
  'string019']
 ...,
 ['string000' 'string001' 'string002' ..., 'string017' 'string018'
  'string019']
 ['string000' 'string001' 'string002' ..., 'string017' 'string018'
  'string019']
 ['string000' 'string001' 'string002' ..., 'string017' 'string018'
  'string019']]
在逐步浏览代码的过程中,我注意到
BlockManagerStorer.write()
方法在两组数据块之间循环(第2002到2006行),该方法大约位于上述调用堆栈的一半。第一个循环运行良好,第二个循环挂起。此外,在下一个堆栈中调用的
GenericStorer.write_array()
方法在第一个过程中具有
value.dtype.type=='numpy.float64'
,但在第二个过程中具有
value.dtype.type=='numpytables.py第1785行上的另一个分支编辑:第一步是写入~800兆欧的文件,因此它似乎是预期输出文件的大部分

最后,如果这是架构/软件风格相关的。我正在运行以下程序:

机器:虚拟机,1个CPU,4Gb RAM,64位
操作系统:Red Hat Enterprise Linux 6(64位)
软件:几天前通过anaconda安装的Python、Pandas、PyTables等。希望在上面的脚本中打印出相关的版本号(作为注释!),但请告诉我其他版本是否合适

需要帮忙吗
James

我测试了您的精确配置,但我使用的是debian/squence

OS: Linux 2.6.32-5-amd64 #1 SMP Sun Sep 23 10:07:46 UTC 2012 x86_64
In [4]: print "Pandas version: " + pd.__version__ # 0.11.0
Pandas version: 0.11.0

In [5]: print "NumPy version: " + np.__version__ # 1.7.1
NumPy version: 1.7.1

In [6]: print "Tables version: " + tables.__version__ # 2.4.0
Tables version: 2.4.0
存储程序
上,字符串状对象(例如索引/列索引)被pickle(与
表相反,表
中的类型是确定的,数据是以本机格式写入的)。你的回溯表明它在泡菜中失败了,这很奇怪;红帽linux可能有一些限制,可能是PyTables 2.4(或pandas)中的一个bug。我无法复制

我会尝试升级到pandas 0.12、PyTables 3.0.0,看看它是否仍然存在


在任何情况下,
表格
格式都应该适合您,并且在任何情况下都提供了许多优势,请参见

我测试了您的精确配置,但我使用debian/Squence除外

OS: Linux 2.6.32-5-amd64 #1 SMP Sun Sep 23 10:07:46 UTC 2012 x86_64
In [4]: print "Pandas version: " + pd.__version__ # 0.11.0
Pandas version: 0.11.0

In [5]: print "NumPy version: " + np.__version__ # 1.7.1
NumPy version: 1.7.1

In [6]: print "Tables version: " + tables.__version__ # 2.4.0
Tables version: 2.4.0
存储程序
上,字符串状对象(例如索引/列索引)被pickle(与
表相反,表
中的类型是确定的,数据是以本机格式写入的)。你的回溯表明它在泡菜中失败了,这很奇怪;红帽linux可能有一些限制,可能是PyTables 2.4(或pandas)中的一个bug。我无法复制

我会尝试升级到pandas 0.12、PyTables 3.0.0,看看它是否仍然存在


在任何情况下,
表格
格式都应该适合您,并且在任何情况下都提供了许多优势,请参见

感谢您的快速响应。你是对的,表格格式在我的简单示例中确实有效,因此步骤1已解决。关于如何更新到最新版本的说明?RHEL存储库甚至不支持pandas(我可以看到),这就是我使用AnacondaAlso的原因。我在使用多索引和其他更复杂的示例编写数据帧时遇到了其他问题。我还有其他工作要做,所以我会在另一个职位上加薪。。。最有可能在下周
pip安装pandas==0.12
<代码>pip安装表==3.0.0
哇,这很简单。。。但我在公司防火墙后面阻止任何移动的东西。我需要在上面打个洞。我说pip正在尝试连接到的说法正确吗?谢谢您的快速回复。你是对的,表格格式在我的简单示例中确实有效,因此步骤1已解决。关于如何更新到最新版本的说明?RHEL存储库甚至不支持pandas(我可以看到),这就是我使用AnacondaAlso的原因。我在使用多索引和其他更复杂的示例编写数据帧时遇到了其他问题。我还有其他工作要做,所以我会在另一个职位上加薪。。。最有可能在下周
pip安装pandas==0.12
<代码>pip安装表==3.0.0哇,这很简单。。。但我在公司防火墙后面阻止任何移动的东西。我需要在上面打个洞。我说pip正在尝试连接到的是正确的吗?