2
我想允许在YAML文件中定义熊猫DataFrame对象,我相信这应该是可能的,因为DataFrame对象是pickleable。使用PyYAML创建熊猫DataFrame对象 - 超递归深度
我剥了下来YAML文件如下,保存为“config.yaml”:
!!python/object/new:pandas.DataFrame [[{'dimension1_id':58,'metric1':10},{'dimension1_id':50,'metric':10}]]
,我使用下面的数据加载到我的Python脚本
f = open('config.yaml')
y = yaml.load(f)
print y
的输出(减少)如下:
File "C:\Python27\lib\site-packages\pandas\core\frame.py", line 2085, in __getattr__
if name in self.columns:
File "properties.pyx", line 55, in pandas.lib.AxisProperty.__get__ (pandas\lib.c:29240)
RuntimeError: maximum recursion depth exceeded while calling a Python object
我使用the PyYAML documentation作为我唯一的信息来源离子在这。
任何人都可以猜测为什么熊猫进入一个无限循环?
编辑:似乎DataFrames对象默认情况下不是可序列化的,并且额外的腿部工作看起来像比它更值得的麻烦。下面是得到由yaml_serializer从只是一个简单的数据框对象创建的YAML文件:
!!python/object/new:pandas.core.frame.DataFrame
state: !!python/object/new:pandas.core.internals.BlockManager
state:
- - !!python/object/apply:numpy.core.multiarray._reconstruct
args:
- &id001 !!python/name:pandas.core.index.Index ''
- [0]
- b
state:
- - 1
- [!!python/long '2']
- &id002 !dtype 'object'
- false
- [dfsd, id]
- [null]
- !!python/object/apply:numpy.core.multiarray._reconstruct
args:
- !!python/name:pandas.core.index.Int64Index ''
- [0]
- b
state:
- - 1
- [!!python/long '2']
- !dtype 'int64'
- false
- "\0\0\0\0\0\0\0\0\x01\0\0\0\0\0\0\0"
- [null]
- - - [!!python/long '23', !!python/long '123']
- [!!python/long '7', !!python/long '123']
- - !!python/object/apply:numpy.core.multiarray._reconstruct
args:
- *id001
- [0]
- b
state:
- - 1
- [!!python/long '2']
- *id002
- false
- [dfsd, id]
- [null]