-
-
Notifications
You must be signed in to change notification settings - Fork 563
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
KaplanMeierFitter: Index Error when adding at_risk_counts #1448
Comments
Maybe related to #1452, which will be fixed in the next release |
I applied the fix to my private fork and the error remained (python 3.9.4, pandas 1.1.5). This indexing is what causes the issue: lifelines/lifelines/plotting.py Line 514 in aa019b1
|
Hm, I'm not able to repro. on the latest lifelines, with pandas 1.5. Could it be a Pandas issue? |
Yes, when I downgrade to 1.1.5, I encounter this problem. |
I used the solution as in here 9b36d87, changing the indexing and the rename (adding "columns=") to get it to work with pandas 1.1.5 (due to project restrictions). if not event_table_slice.loc[:tick].empty:
event_table_slice = (
event_table_slice.loc[:tick, ["at_risk", "censored", "observed"]]
.agg({"at_risk": lambda x: x.tail(1).values, "censored": "sum", "observed": "sum"}) # see #1385
.rename(columns={"at_risk": "At risk", "censored": "Censored", "observed": "Events"})
.fillna(0)
)
counts.extend([int(event_table_slice[c]) for c in event_table_slice[rows_to_show]])
else:
counts.extend([0 for _ in range(n_rows)]) The easiest solution would be recommending to people to upgrade to the latest pandas. |
Python 3.8 (conda env)
lifelines-0.27.1
Using the into on the docs website:
https://lifelines.readthedocs.io/en/latest/Survival%20analysis%20with%20lifelines.html
The text was updated successfully, but these errors were encountered: