Skip to content

Method to convert wide to long format triangle #218

Answered by jbogaardt
xne0n asked this question in Q&A
Discussion options

You must be logged in to vote

Hi @xne0n ,

Thanks for the question. It's not documented. We should probably mention something in the docs or figure out how to support wide. I'd use pandas.unstack to get there. Something like this:

import chainladder as cl

# Suppose you have a wide triangle (perhaps copied from Excel clipboard...)
df = cl.load_sample('raa').to_frame()

# You can use pandas unstack to make wide format long
df = df.unstack().dropna().reset_index()
# make sure you have good column labels
df.columns = ['age', 'origin', 'values']
# and make a date-like valuation
df['valuation'] = (df['origin'].dt.year + df['age'] / 12 - 1).astype(int)
# Finally make a Triangle
cl.Triangle(df, origin='origin', development='v…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@xne0n
Comment options

Answer selected by xne0n
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants