DataInfo#
- class pharmpy.model.DataInfo(columns=(), path=None, separator=',', missing_data_token=None)[source]#
Bases:
Sequence
,Immutable
Metadata for the dataset
Can be indexed to get ColumnInfo for the columns.
- Parameters:
columns (list) – List of column names
path (Path) – Path to dataset file
separator (str) – Character or regexp separator for dataset
missing_data_token (str) – Token for missing data
Attributes Summary
Descriptor indexer
The dv column
The id column
The idv column
Token for missing data
All column names
Path of dataset file
Separator for dataset file
Type indexer
All column types
Methods Summary
create
([columns, path, separator, ...])from_dict
(d)from_json
(s)Create DataInfo from JSON string
Create a dictionary from column names to pandas dtypes
read_json
(path)Read DataInfo from JSON file
replace
(**kwargs)set_column
(col)Set ColumnInfo of an existing column of the same name
set_dv_column
(name)set_id_column
(name)set_idv_column
(name)set_types
(value)Set types for all columns
to_dict
()to_json
([path])Attributes Documentation
- descriptorix#
Descriptor indexer
Example
>>> from pharmpy.modeling import load_example_model >>> model = load_example_model("pheno") >>> model.datainfo.descriptorix['body weight'].names ['WGT']
- dv_column#
The dv column
Examples
>>> from pharmpy.modeling import load_example_model >>> model = load_example_model("pheno") >>> model.datainfo.dv_column.name 'DV'
- id_column#
The id column
Examples
>>> from pharmpy.modeling import load_example_model >>> model = load_example_model("pheno") >>> model.datainfo.id_column.name 'ID'
- idv_column#
The idv column
Examples
>>> from pharmpy.modeling import load_example_model >>> model = load_example_model("pheno") >>> model.datainfo.idv_column.name 'TIME'
- missing_data_token#
Token for missing data
- names#
All column names
Examples
>>> from pharmpy.modeling import load_example_model >>> model = load_example_model("pheno") >>> model.datainfo.names ['ID', 'TIME', 'AMT', 'WGT', 'APGR', 'DV', 'FA1', 'FA2']
- path#
Path of dataset file
Examples
>>> from pharmpy.modeling import load_example_model >>> model = load_example_model("pheno") >>> str(model.datainfo.path).replace('\\', '/') '.../pharmpy/internals/example_models/pheno.dta'
- separator#
Separator for dataset file
Can be a single character or a regular expression string.
- typeix#
Type indexer
Example
>>> from pharmpy.modeling import load_example_model >>> model = load_example_model("pheno") >>> model.datainfo.typeix['covariate'].names ['WGT', 'APGR']
- types#
All column types
Methods Documentation
- static from_json(s)[source]#
Create DataInfo from JSON string
- Parameters:
s (str) – JSON string
- Returns:
DataInfo – Created DataInfo object
- get_dtype_dict()[source]#
Create a dictionary from column names to pandas dtypes
This can be used as input to some pandas functions to convert column to the correct pandas dtype.
- Returns:
dict – Column name to pandas dtype
Examples
>>> from pharmpy.modeling import * >>> model = load_example_model("pheno") >>> model.datainfo.get_dtype_dict() {'ID': 'int32', 'TIME': 'float64', 'AMT': 'float64', 'WGT': 'float64', 'APGR': 'float64', 'DV': 'float64', 'FA1': 'float64', 'FA2': 'float64'}
- static read_json(path)[source]#
Read DataInfo from JSON file
- Parameters:
path (Path or str) – Path to JSON datainfo file
- Returns:
DataInfo – Created DataInfo object
- set_column(col)[source]#
Set ColumnInfo of an existing column of the same name
- Parameters:
col (ColumnInfo) – New ColumnInfo
- Returns:
DataInfo – Updated DataInfo