pandas.io.stata.StataReader.value_labels — pandas 3.0.0rc0+52.gb43b95d2b4 documentation (original) (raw)

StataReader.value_labels()[source]#

Return a nested dict associating each variable name to its value and label.

This method retrieves the value labels from a Stata file. Value labels are mappings between the coded values and their corresponding descriptive labels in a Stata dataset.

Returns:

dict

A python dictionary.

See also

read_stata

Read Stata file into DataFrame.

DataFrame.to_stata

Export DataFrame object to Stata dta format.

Examples

df = pd.DataFrame([[1, 2], [3, 4]], columns=["col_1", "col_2"]) time_stamp = pd.Timestamp(2000, 2, 29, 14, 21) path = "/My_path/filename.dta" value_labels = {"col_1": {3: "x"}} df.to_stata( ... path, ... time_stamp=time_stamp, ... value_labels=value_labels, ... version=None, ... ) with pd.io.stata.StataReader(path) as reader: ... print(reader.value_labels()) {'col_1': {3: 'x'}} pd.read_stata(path) index col_1 col_2 0 0 1 2 1 1 x 4