sksurv.io.loadarff#
- sksurv.io.loadarff(filename, *, output_type='pandas')[source]#
Load ARFF file.
- Parameters:
filename (str or file-like) – Path to ARFF file, or file-like object to read from.
output_type ({"pandas", "polars"}, default="pandas") – Dataframe library for the returned frame. Nominal columns become
pd.Categorical(ordered=False)(pandas) orpl.Enum(declared_categories)(polars), preserving the full declared category list including labels absent from the data.
- Returns:
data_frame – DataFrame containing data of the ARFF file. The dataframe library follows
output_type.- Return type:
pandas.DataFrameorpolars.DataFrame
See also
scipy.io.arff.loadarffThe underlying function that reads the ARFF file.
Examples
>>> from io import StringIO >>> from sksurv.io import loadarff >>> >>> # Create a dummy ARFF file >>> arff_content = ''' ... @relation test_data ... @attribute feature1 numeric ... @attribute feature2 numeric ... @attribute class {A,B,C} ... @data ... 1.0,2.0,A ... 3.0,4.0,B ... 5.0,6.0,C ... ''' >>> >>> # Load the ARFF file as pandas (default) >>> with StringIO(arff_content) as f: ... data = loadarff(f) >>> >>> print(data) class feature1 feature2 0 A 1.0 2.0 1 B 3.0 4.0 2 C 5.0 6.0
Load as polars; nominal columns become
pl.Enum:>>> with StringIO(arff_content) as f: ... data_pl = loadarff(f, output_type="polars") >>> data_pl["class"].dtype Enum(categories=['A', 'B', 'C'])