Skip to main content
`Ctrl`+`K`

# pandas.io.stata.StataReader.variable_labels

StataReader.variable_labels()

  Return a dict associating each variable name with corresponding label.

  This method retrieves variable labels from a Stata file. Variable labels are mappings between variable names 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"
      >>> variable_labels = {"col_1": "This is an example"}
      >>> df.to_stata(
      ...     path,
      ...     time_stamp=time_stamp,
      ...     variable_labels=variable_labels,
      ...     version=None,
      ... )
      >>> with pd.io.stata.StataReader(path) as reader:
      ...     print(reader.variable_labels())
      {'index': '', 'col_1': 'This is an example', 'col_2': ''}
      >>> pd.read_stata(path)
          index col_1 col_2
      0       0    1    2
      1       1    3    4