Importing Data #316
-
Hey, just want to start by saying this is an exciting package. after reserving in excel for years, I am really excited for find a package that handles the data in this way and creates an environment that follows the way that I think about data and process. I am simultaneously working my way up both the Python and the chainladder learning curve, so forgive a noob question I am trying to pull in quarterly development triangles where the format looks like this YYYY-Qq, so for example 2021Q4. chain ladder seems to take the data in, although it does throw a warning about data being out of bounds, but when I try to look at the data, it is giving me garbage. see example. Pulling from Access |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 6 replies
-
Hi @Obalus2022 , Syntactically, your code looks fine. The warning about some items having some development dates before the origin date indicates the negative development ages, so the data should be checked. Some other possible things to check:
Hope this helps, if not, I may need you to provide a bit more context and/or a reproducible example with fake data. |
Beta Was this translation helpful? Give feedback.
-
Does this look like what you want? import chainladder as cl
import pandas as pd
from io import StringIO
data = """
AccidentQuarter|ReportedQuarter|RiskCode|PDLALAE|OSLR
2006-Q1|2006-Q1|ARP|1199961.6| 0.0
2006-Q1|2006-Q2|ARP|0.0| 0.0
2006-Q2|2006-Q2|ARP|106595.2| 0.0
2006-Q2|2006-Q3|ARP|481599.2| 0.0
2006-Q3|2006-Q3|ARP|1116264.8| 0.0
2006-Q3|2006-Q4|ARP|217327.6| 0.0
2006-Q3|2007-Q1|ARP|211620.0| 0.0
2006-Q3|2007-Q2|ARP|0.0| 0.0
2006-Q4|2006-Q4|ARP|358700.0| 0.0
2006-Q4|2007-Q1|ARP|56620.0| 0.0
2006-Q4|2007-Q2|ARP|1213920.4| 0.0
2006-Q4|2008-Q1|ARP|908103.6| 0.0
2006-Q4|2008-Q4|ARP|0.0| 0.0"""
triangle = cl.Triangle(
pd.read_csv(StringIO(data), delimiter='|'),
origin='AccidentQuarter', development='ReportedQuarter',
index='RiskCode', columns=['PDLALAE', 'OSLR'],
origin_format='%Y-%q', development_format='%Y-%q',
cumulative=False)
triangle[triangle['RiskCode']=='ARP']['PDLALAE'].sum(axis='index').incr_to_cum() |
Beta Was this translation helpful? Give feedback.
-
Beta Was this translation helpful? Give feedback.
-
No, I do not suggest you convert your data to a string. Let's look instead at the difference in the code (chainladder syntax only) with expanded commentary: (
triangle[triangle['RiskCode']=='ARP']['PDLALAE'] # Filters for some index and column, Fine
.sum(axis='index') # Deliberately summing the index axis. If there is only one index .e.g. ARP, this is unnecessary.
.incr_to_cum() # This method takes our incremental triangle and makes it cumulative which is what I think you want.
) Your original code with commentary: (
triangle[triangle['RiskCode']=='ARP']['PDLALAE'] # Filters for some index and column, Fine
.sum() # No axis is specified in sum, so this sums the origin axis since we have a (1,1,12,12) shaped triangle. origin is the first axis with length > 1
.to_frame() # this converts it to a pandas dataframe which precludes using the estimators in chainladder.
) It sounds to me like you just need to accumulate your triangle with |
Beta Was this translation helpful? Give feedback.
No, I do not suggest you convert your data to a string. Let's look instead at the difference in the code (chainladder syntax only) with expanded commentary:
Your original code with commentary: