Export DataFrame object to Stata dta format. Writes the DataFrame to a Stata dataset file. "dta" files contain a Stata dataset. Parameters ---------- path : str, path object, or buffer String, path object (implementing ``os.PathLike[str]
(
self,
path: FilePath | WriteBuffer[bytes],
*,
convert_dates: dict[Hashable, str] | None = None,
write_index: bool = True,
byteorder: ToStataByteorder | None = None,
time_stamp: datetime.datetime | None = None,
data_label: str | None = None,
variable_labels: dict[Hashable, str] | None = None,
version: int | None = 114,
convert_strl: Sequence[Hashable] | None = None,
compression: CompressionOptions = "infer",
storage_options: StorageOptions | None = None,
value_labels: dict[Hashable, dict[float, str]] | None = None,
)
| 2663 | return cls._from_mgr(mgr, axes=mgr.axes) |
| 2664 | |
| 2665 | def to_stata( |
| 2666 | self, |
| 2667 | path: FilePath | WriteBuffer[bytes], |
| 2668 | *, |
| 2669 | convert_dates: dict[Hashable, str] | None = None, |
| 2670 | write_index: bool = True, |
| 2671 | byteorder: ToStataByteorder | None = None, |
| 2672 | time_stamp: datetime.datetime | None = None, |
| 2673 | data_label: str | None = None, |
| 2674 | variable_labels: dict[Hashable, str] | None = None, |
| 2675 | version: int | None = 114, |
| 2676 | convert_strl: Sequence[Hashable] | None = None, |
| 2677 | compression: CompressionOptions = "infer", |
| 2678 | storage_options: StorageOptions | None = None, |
| 2679 | value_labels: dict[Hashable, dict[float, str]] | None = None, |
| 2680 | ) -> None: |
| 2681 | """ |
| 2682 | Export DataFrame object to Stata dta format. |
| 2683 | |
| 2684 | Writes the DataFrame to a Stata dataset file. |
| 2685 | "dta" files contain a Stata dataset. |
| 2686 | |
| 2687 | Parameters |
| 2688 | ---------- |
| 2689 | path : str, path object, or buffer |
| 2690 | String, path object (implementing ``os.PathLike[str]``), or file-like |
| 2691 | object implementing a binary ``write()`` function. |
| 2692 | |
| 2693 | convert_dates : dict |
| 2694 | Dictionary mapping columns containing datetime types to stata |
| 2695 | internal format to use when writing the dates. Options are 'tc', |
| 2696 | 'td', 'tm', 'tw', 'th', 'tq', 'ty'. Column can be either an integer |
| 2697 | or a name. Datetime columns that do not have a conversion type |
| 2698 | specified will be converted to 'tc'. Raises NotImplementedError if |
| 2699 | a datetime column has timezone information. |
| 2700 | write_index : bool |
| 2701 | Write the index to Stata dataset. |
| 2702 | byteorder : str |
| 2703 | Can be ">", "<", "little", or "big". default is `sys.byteorder`. |
| 2704 | time_stamp : datetime |
| 2705 | A datetime to use as file creation date. Default is the current |
| 2706 | time. |
| 2707 | data_label : str, optional |
| 2708 | A label for the data set. Must be 80 characters or smaller. |
| 2709 | variable_labels : dict |
| 2710 | Dictionary containing columns as keys and variable labels as |
| 2711 | values. Each label must be 80 characters or smaller. |
| 2712 | version : {114, 117, 118, 119, None}, default 114 |
| 2713 | Version to use in the output dta file. Set to None to let pandas |
| 2714 | decide between 118 or 119 formats depending on the number of |
| 2715 | columns in the frame. Version 114 can be read by Stata 10 and |
| 2716 | later. Version 117 can be read by Stata 13 or later. Version 118 |
| 2717 | is supported in Stata 14 and later. Version 119 is supported in |
| 2718 | Stata 15 and later. Version 114 limits string variables to 244 |
| 2719 | characters or fewer while versions 117 and later allow strings |
| 2720 | with lengths up to 2,000,000 characters. Versions 118 and 119 |
| 2721 | support Unicode characters, and version 119 supports more than |
| 2722 | 32,767 variables. |