无法将python chainladder三角形导出到excel工作表

无法将python chainladder三角形导出到excel工作表,python,Python,我正在探索chainladder包。我尝试将三角形结构导出到excel表格中。但它抛出了一个错误。有没有人遇到过这样的问题。我正在使用chainladder==0.7.9和pandas==0.24.2。下面是我通过阅读他们的文档而得到的简单代码 我得到以下错误: --------------------------------------------------------------------------- AttributeError

我正在探索
chainladder
包。我尝试将三角形结构导出到excel表格中。但它抛出了一个错误。有没有人遇到过这样的问题。我正在使用chainladder==0.7.9和pandas==0.24.2。下面是我通过阅读他们的文档而得到的简单代码

我得到以下错误:

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
e:\pyworkspace37\chainladderdemo\venv\lib\site-packages\chainladder\utils\exhibits.py in load_template(template, env, **kwargs)
     24     try:
---> 25         return load_yaml(template, env, **kwargs)
     26     except:

e:\pyworkspace37\chainladderdemo\venv\lib\site-packages\xlcompose\templates.py in load_yaml(template, env, str_only, **kwargs)
    108     else:
--> 109         return _make_xlc(yaml.load(template, Loader=yaml.SafeLoader), **kwargs)
    110 

e:\pyworkspace37\chainladderdemo\venv\lib\site-packages\xlcompose\templates.py in _make_xlc(template, **kwargs)
     51                 return core.Tabs(*[('Sheet1', item) for item in tabs])
---> 52         key = list(template.keys())[0]
     53         if key in ['Row', 'Column']:

AttributeError: 'str' object has no attribute 'keys'

During handling of the above exception, another exception occurred:

AttributeError                            Traceback (most recent call last)
<ipython-input-17-270670213d97> in <module>
----> 1 cl.load_template('triangle', triangle=raa.latest_diagonal).to_excel('raa_example.xlsx')
      2 #,type(raa.latest_diagonal)
      3 type(raa_model.ultimate_)

e:\pyworkspace37\chainladderdemo\venv\lib\site-packages\chainladder\utils\exhibits.py in load_template(template, env, **kwargs)
     26     except:
     27         template = os.path.join(path, "templates", template.lower() + ".yaml")
---> 28         return load_yaml(template, env, **kwargs)

e:\pyworkspace37\chainladderdemo\venv\lib\site-packages\xlcompose\templates.py in load_yaml(template, env, str_only, **kwargs)
    107         return template
    108     else:
--> 109         return _make_xlc(yaml.load(template, Loader=yaml.SafeLoader), **kwargs)
    110 
    111 def load_json(template, env=None, **kwargs):

e:\pyworkspace37\chainladderdemo\venv\lib\site-packages\xlcompose\templates.py in _make_xlc(template, **kwargs)
     50             except:
     51                 return core.Tabs(*[('Sheet1', item) for item in tabs])
---> 52         key = list(template.keys())[0]
     53         if key in ['Row', 'Column']:
     54             return getattr(core, key)(*[_make_xlc(element, **kwargs)

AttributeError: 'str' object has no attribute 'keys'
---------------------------------------------------------------------------
AttributeError回溯(最近一次呼叫上次)
e:\pyworkspace37\chainladderdemo\venv\lib\site packages\chainladder\utils\examples.py加载模板(模板,env,**kwargs)
24试:
--->25返回荷载(模板、环境、**kwargs)
26除:
e:\pyworkspace37\chainladderdemo\venv\lib\site packages\xlcompose\templates.py in load_yaml(仅限模板、环境、str_,**kwargs)
108.其他:
-->109返回(yaml.load(模板,加载程序=yaml.SafeLoader),**kwargs)
110
e:\pyworkspace37\chainladderdemo\venv\lib\site packages\xlcompose\templates.py在(模板,**kwargs)中
51返回旧件。制表符(*[('Sheet1',项目)用于制表符中的项目])
--->52键=列表(template.keys())[0]
53如果输入[‘行’、‘列’]:
AttributeError:“str”对象没有属性“keys”
在处理上述异常期间,发生了另一个异常:
AttributeError回溯(最近一次呼叫上次)
在里面
---->1 cl.load_模板('triangle',triangle=raa.latest_diagonal).到excel('raa_example.xlsx'))
2#,类型(raa.最新对角线)
3型(raa\U型。最终型)
e:\pyworkspace37\chainladderdemo\venv\lib\site packages\chainladder\utils\examples.py加载模板(模板,env,**kwargs)
26除:
27 template=os.path.join(路径“templates”,template.lower()+“.yaml”)
--->28返回荷载(模板、环境、**kwargs)
e:\pyworkspace37\chainladderdemo\venv\lib\site packages\xlcompose\templates.py in load_yaml(仅限模板、环境、str_,**kwargs)
107返回模板
108.其他:
-->109返回(yaml.load(模板,加载程序=yaml.SafeLoader),**kwargs)
110
111 def load_json(模板,env=None,**kwargs):
e:\pyworkspace37\chainladderdemo\venv\lib\site packages\xlcompose\templates.py在(模板,**kwargs)中
50除:
51返回旧件。制表符(*[('Sheet1',项目)用于制表符中的项目])
--->52键=列表(template.keys())[0]
53如果输入[‘行’、‘列’]:
54返回getattr(核心,键)(*[\u make\u xlc(元素,**kwargs)
AttributeError:“str”对象没有属性“keys”

如果我遗漏了一些愚蠢的东西,请告诉我。

load\u template
用于加载包含Excel文件规格的YAML模板。此特定模板文件旨在为规则三角形而不是对角线创建标准展示。模板用于包含复杂的布局、格式和逻辑

这应该可以解决这个问题:

cl.load_模板('triangle',triangle=raa)。到excel('raa_example.xlsx'))
如果只想将对角线导出到Excel,则无需模板即可:

raa.latest_diagonal.to_excel('raa_example.xlsx')
# or
cl.DataFrame(raa.latest_diagonal).to_excel('raa_example.xlsx')
raa.latest_diagonal.to_excel('raa_example.xlsx')
# or
cl.DataFrame(raa.latest_diagonal).to_excel('raa_example.xlsx')