techtonique_apis.techto_survival

 1import tempfile
 2import pandas as pd
 3from xlwings import func, arg, ret
 4from .techtonique_apis import TechtoniqueAPI
 5
 6api = TechtoniqueAPI()
 7
 8
 9@func
10@arg("df", index=False, doc="Excel range with columns for survival data.")
11@arg("method", doc='Survival analysis method (default: "km")')
12@arg("patient_id", doc="(For machine learning 'method's) Patient ID for individual survival curve")
13@ret(index=False, doc="Survival curve results as a table for Excel")
14def techto_survival(
15    df: pd.DataFrame,
16    method: str = "km",
17    patient_id: int = None,
18) -> pd.DataFrame:
19    """
20    Survival analysis: pass a survival dataset as a DataFrame from Excel, return survival curve.
21
22    Excel/xlwings custom function: Survival analysis on a table from Excel using the Techtonique API.
23
24    Parameters
25    ----------
26
27    df : pd.DataFrame
28        The input survival data as a DataFrame (from Excel range).
29
30    method : str, default "km"
31        Survival analysis method to use.
32
33    patient_id : int, optional
34        For machine learning methods, patient ID for individual survival curve.
35
36    Returns
37    -------
38
39    pd.DataFrame
40        Survival curve results as a DataFrame for Excel.
41
42    ---
43    xlwings lite docstring (for Excel help):
44    Survival analysis on a table from Excel using the Techtonique API.
45    - df: Excel range with columns for survival data.
46    - method: Survival analysis method (default: km).
47    - patient_id: (For machine learning methods) Patient ID for individual survival curve.
48    Returns: Survival curve results as a table for Excel.
49    """
50    with tempfile.NamedTemporaryFile(suffix=".csv", delete=False) as tmp:
51        df.to_csv(tmp.name, index=False)
52        result = api.survival_curve(
53            file_path=tmp.name,
54            method=method,
55            patient_id=patient_id,
56        )
57    return pd.DataFrame(result)
@func
@arg('df', index=False, doc='Excel range with columns for survival data.')
@arg('method', doc='Survival analysis method (default: "km")')
@arg('patient_id', doc="(For machine learning 'method's) Patient ID for individual survival curve")
@ret(index=False, doc='Survival curve results as a table for Excel')
def techto_survival( df: pandas.core.frame.DataFrame, method: str = 'km', patient_id: int = None) -> pandas.core.frame.DataFrame:
10@func
11@arg("df", index=False, doc="Excel range with columns for survival data.")
12@arg("method", doc='Survival analysis method (default: "km")')
13@arg("patient_id", doc="(For machine learning 'method's) Patient ID for individual survival curve")
14@ret(index=False, doc="Survival curve results as a table for Excel")
15def techto_survival(
16    df: pd.DataFrame,
17    method: str = "km",
18    patient_id: int = None,
19) -> pd.DataFrame:
20    """
21    Survival analysis: pass a survival dataset as a DataFrame from Excel, return survival curve.
22
23    Excel/xlwings custom function: Survival analysis on a table from Excel using the Techtonique API.
24
25    Parameters
26    ----------
27
28    df : pd.DataFrame
29        The input survival data as a DataFrame (from Excel range).
30
31    method : str, default "km"
32        Survival analysis method to use.
33
34    patient_id : int, optional
35        For machine learning methods, patient ID for individual survival curve.
36
37    Returns
38    -------
39
40    pd.DataFrame
41        Survival curve results as a DataFrame for Excel.
42
43    ---
44    xlwings lite docstring (for Excel help):
45    Survival analysis on a table from Excel using the Techtonique API.
46    - df: Excel range with columns for survival data.
47    - method: Survival analysis method (default: km).
48    - patient_id: (For machine learning methods) Patient ID for individual survival curve.
49    Returns: Survival curve results as a table for Excel.
50    """
51    with tempfile.NamedTemporaryFile(suffix=".csv", delete=False) as tmp:
52        df.to_csv(tmp.name, index=False)
53        result = api.survival_curve(
54            file_path=tmp.name,
55            method=method,
56            patient_id=patient_id,
57        )
58    return pd.DataFrame(result)

Survival analysis: pass a survival dataset as a DataFrame from Excel, return survival curve.

Excel/xlwings custom function: Survival analysis on a table from Excel using the Techtonique API.

Parameters

df : pd.DataFrame The input survival data as a DataFrame (from Excel range).

method : str, default "km" Survival analysis method to use.

patient_id : int, optional For machine learning methods, patient ID for individual survival curve.

Returns

pd.DataFrame Survival curve results as a DataFrame for Excel.


xlwings lite docstring (for Excel help): Survival analysis on a table from Excel using the Techtonique API.

  • df: Excel range with columns for survival data.
  • method: Survival analysis method (default: km).
  • patient_id: (For machine learning methods) Patient ID for individual survival curve. Returns: Survival curve results as a table for Excel.