FIS Prophet模型点文件检查器和处理器
mpfi的Python项目详细描述
强积金检查员
这是一个python库,用于处理精算软件Prophet,由FIS(而不是Facebook为时间序列预测创建的先知)制作的模型点的处理。在
它利用了Pandas库的功能,因此您可以轻松地解析、处理和过滤模型点。在
系统要求
Python>;=3.6
对于不熟悉Python的Windows用户,我们建议使用Anaconda安装Python和Pandas
- 对于不熟悉Anaconda/python的用户,请在安装过程中选择“export to PATH”,这样您就可以更轻松地使用python运行了
安装
对于没有网络限制的普通计算机:
pip install mpfi
如果在安装过程中遇到错误,可以将trusted-host
添加到install命令或使用wheel文件:
车轮锉法:
- 在
从https://pypi.org/project/mpfi/#files下载mpfi的wheel文件
在 - 在
通过运行以下命令安装控制盘:
在
pip install "C:/the-path-to-your-file.whl"
使用
快速浏览
# in a python command shell, or as Python scriptimportmpfi# mpfi.load or mpfi.load_all returns a pandas DataFrame object# load the first model point with file name C123456 in the list of paths provided in the configdf=mpfi.load('C123456')# load all C product model points in the first folder found with 201912df=mpfi.load_all('201912','C*.PRO')# output the data as model point files in folder `all-model-points`mpfi.export(df,'all-model-points')# output (consolidate) all model points in single file `all-model-points.PRO` without the header# header means the 3 extra header lines in the MPF: OUTPUT_FORMAT, NUMLINES and VARIABLE_TYPESmpfi.export(df,'all-model-points',{'split_into_prod':False,'write_header':False})# same as above but also include the _FILE_NAME and exclude the SPCODE and AGE_AT_ENTRY columns# header means the 3 extra header lines in the MPF: OUTPUT_FORMAT, NUMLINES and VARIABLE_TYPESmpfi.export(df,'all-model-points',{'split_into_prod':False,'write_header':False,'include_columns':['_FILE_NAME'],'exclude_columns':['SPCODE','AGE_AT_ENTRY'],})
参考(数据帧操作示例)
# select model points with policy number 12345678df[df.POL_NUMBER=='12345678']# inspect the model pointimportpandasaspdpd.options.display.max_rows=None# To set pandas to display all rowsdf[df.POL_NUMBER=='12345678'].T# display it. (T means transpose)pd.options.display.max_rows=60# restore display options# select model points with policy number 12345678, with its SPCODE and SUM_ASSURED columnsdf[df.POL_NUMBER=='12345678'][['SPCODE','SUM_ASSURED']]# PREM_FREQ is 1 and plan code is either ABC or DEFdf[(df.PREM_FREQ==1)&(df.PLAN_CODE.isin(['ABC','DEF']))]# PREM_FREQ is 1 or EFF_YEAR is 2010df[(df.PREM_FREQ==1)|(df.EFF_YEAR==2010)]# Set PREM_FREQ to 12 for all model pointsdf['PREM_FREQ']=12# Edit/Create exchange rate based on currencydf['exchange_rate']=data['CURRENCY'].map({'HKD':1/7.8,'USD':1,'MOP':1/7.8})# Filter by _PROD_CODE `C12345` or `C23456` and output the selection to csv for "easier" manipulationdf[(df._PROD_NAME=='C12345')|(df._PROD_NAME=='C23456')].to_csv('C12345-C23456.csv')
有关选择和编辑数据帧的详细信息,请访问documentation of Pandas。在
配置文件
在使用库之前,您应该为您的公司和工作环境创建并配置规范文件mpfi-config.py
。在
当执行任何load
函数时,库将自动在当前路径中加载配置文件mpfi-config.py
。在
您可以运行mpfi.generate_config()
来创建一个示例配置文件,以便进一步修改它。配置文件包含解释,因此它应该是自解释的。在
importmpfimpfi.generate_config()# Create mpfi-config.py in the current folder for editing
如需使用图书馆,建议您在每月/每个地区填写强积金路径。你可以通过设定限制来选择正确的强积金。在
加载单个模型点文件
产品代码本身将被插入到配置中指定列名的DataFrame中(默认值为_PROD_NAME
)。在
类似地,完整的文件路径作为_FILE_NAME
插入。在
importmpfi# Assuming config extension is .PRO# load the first C123456.PRO found in the list of MPF_FOLDERSdf=mpfi.load('C123456')# a pandas DataFrame object# load the first C123456.PRO found in the list of MPF_FOLDERS where the full file path contains 201912df=mpfi.load('C123456','201912')# a pandas DataFrame object# load the first C123456.PRO found in the list of MPF_FOLDERS# where the full file path contains both 201912 and HKdf=mpfi.load('C123456',['HK','201912'])# a pandas DataFrame object
在文件夹
中加载多个模型点文件mpfi.load_all(containing_text,file_pattern=None)
产品代码本身将被插入到配置中指定列名的DataFrame中(默认值为_PROD_NAME
)
示例
importmpfi# Assuming config extension is .PRO# load all *.PRO in the first MPF folder containing 201912df=mpfi.load_all('201912')# load all C*.rpt in the first MPF folder containing both HK and 201912# Note that the config extension is ignored when a specific file pattern is provideddf=mpfi.load_all(['201912','HK'],'C*.rpt')
正在加载.fac表文件
有时您需要加载一些用于DCS/Prophet的.fac
文件,以进行额外的映射。在
这个库提供了一个加载fac
文件的助手,它根据.fac
文件自动创建相应的索引列。在
importmpfimy_data=mpfi.load_fac('prem_rate.fac')# a pandas DataFrame object
动机
在系统设计中,同一类型的数据应该存储在一个文件或一个数据库表中。这可以确保一致性,并便于索引、搜索和操作数据。在
然而,FIS Prophet自身的结构是“鼓励”用户将同一类型的数据(策略数据)拆分为多个文件(不同的产品代码),即模型点文件“MPF”。这给用户管理和操作不同文件夹中的数百个文件带来了问题,因为在大多数保险公司中,每个不同的产品代码、月份和地区都使用不同的模型点文件,而最佳做法是将所有这些文件存储在一个数据库中。在
更糟糕的是,虽然一个普通的csv文件很容易解析和分析,但Prophet却让模型点文件更难解析,因为DCS(数据转换系统旨在使生成模型点文件变得“容易”)产生额外的页眉和页脚行。这同样适用于Prophet和DCS使用的外部表,即.fac文件。在
由于DCS的老式语法,代码通常是不必要的复杂的;而对于DCS配置(例如输入格式)不作为代码存储,适当的版本控制nd代码协作是不可能的,因此我们到处可以看到v1
,v2
,v202012
,我们经常会遇到需要手动合并DCS的情况,这既繁琐又耗时。在
为了缓解上述问题带来的维护困难,我编写了这个库来创建更为用户友好的方法来创建、编辑和过滤模型点。在
在Pandas库中使用Python是管理和创建模型点文件的最佳方法之一,这要归功于具有强大社区支持的现代Python特性和语法,以及使用Pandas处理大量数据的能力。在
许可证
此项目是根据MIT License授权的。在
- 项目
标签: