@@ -2737,6 +2737,30 @@ def _encode_strings(self) -> None:
2737
2737
def write_file (self ) -> None :
2738
2738
"""
2739
2739
Export DataFrame object to Stata dta format.
2740
+
2741
+ Examples
2742
+ --------
2743
+ >>> df = pd.DataFrame({"fully_labelled": [1, 2, 3, 3, 1],
2744
+ ... "partially_labelled": [1.0, 2.0, np.nan, 9.0, np.nan],
2745
+ ... "Y": [7, 7, 9, 8, 10],
2746
+ ... "Z": pd.Categorical(["j", "k", "l", "k", "j"]),
2747
+ ... })
2748
+ >>> path = "/My_path/filename.dta"
2749
+ >>> labels = {"fully_labelled": {1: "one", 2: "two", 3: "three"},
2750
+ ... "partially_labelled": {1.0: "one", 2.0: "two"},
2751
+ ... }
2752
+ >>> writer = pd.io.stata.StataWriter(path,
2753
+ ... df,
2754
+ ... value_labels=labels) # doctest: +SKIP
2755
+ >>> writer.write_file() # doctest: +SKIP
2756
+ >>> df = pd.read_stata(path) # doctest: +SKIP
2757
+ >>> df # doctest: +SKIP
2758
+ index fully_labelled partially_labeled Y Z
2759
+ 0 0 one one 7 j
2760
+ 1 1 two two 7 k
2761
+ 2 2 three NaN 9 l
2762
+ 3 3 three 9.0 8 k
2763
+ 4 4 one NaN 10 j
2740
2764
"""
2741
2765
with get_handle (
2742
2766
self ._fname ,
0 commit comments