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]