Issue with chainladder.Triangle Output - Column Misalignment in Python 3.11.5 & chainladder 0.8.23 #551
Unanswered
copythontest
asked this question in
Q&A
Replies: 1 comment 1 reply
-
Hard to tell with the above but the suggestions I would make are:
|
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I'm 1st time using the chainladder library in Python (version 3.11.5, chainladder version 0.8.23) to process claims data. However, when I create a Triangle object, the output appears misaligned. The cumulative development periods seem to be shifted, with data appearing in the 24th column instead of the expected 12th column.
import os
import pandas as pd
import chainladder as cl
script_dir = os.getcwd()
file_path = os.path.join(script_dir, "test_file_data.xlsx")
df = pd.read_excel(file_path, sheet_name="Sheet1")
expected_columns = {"accident_year": "origin", "dev_period": "development", "claims_incurred": "values"}
missing_cols = [col for col in expected_columns.keys() if col not in df.columns]
if missing_cols:
raise ValueError(f"Missing required columns: {missing_cols}")
df.rename(columns=expected_columns, inplace=True)
df.dropna(subset=["origin", "development", "values"], inplace=True)
df["origin"] = pd.to_numeric(df["origin"], errors="coerce")
df["development"] = pd.to_numeric(df["development"], errors="coerce")
df["values"] = pd.to_numeric(df["values"], errors="coerce")
df["development"] = df["origin"] + df["development"]
triangle = cl.Triangle(df, origin="origin", development="development", values="values")
print(triangle)
Sample Data
Unexpected Output
The output appears to have a shift, showing values under the 24th development period column instead of the 12th column: (output values are accurate, but in this format )
Question
Why is my triangle output misaligned?
Is there an issue with how I'm defining the development period ?
What would be the correct way to ensure the development periods align properly in the Triangle object?
Any insights or suggestions would be greatly appreciated!
Beta Was this translation helpful? Give feedback.
All reactions