importdta.set_var_labels
importdta.set_var_labels(
df,
labels,
*,
overwrite=True,
update_mtable_defaults=False,
)Set variable labels on a DataFrame and optionally sync them to MTable.DEFAULT_LABELS.
Labels are stored in df.attrs[‘variable_labels’] as a plain dict. Only columns present in df are written.
Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| df | pandas.DataFrame | DataFrame to modify. | required |
| labels | dict | Mapping {column_name: label} to set. | required |
| overwrite | bool | If True, replace existing labels for given columns; if False, only fill missing. | True |
| update_mtable_defaults | bool | If True, merge the resulting labels dict into MTable.DEFAULT_LABELS (respecting the overwrite policy). | False |
Examples
>>> set_var_labels(df, {"mpg": "Miles per gallon"}, update_mtable_defaults=True)
>>> get_var_labels(df)