Skip to content

Commit 860f474

Browse files
committed
Updated examples
1 parent 99df7da commit 860f474

File tree

1 file changed

+19
-16
lines changed

1 file changed

+19
-16
lines changed

pandas/core/frame.py

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1856,12 +1856,15 @@ def to_stata(self, fname, convert_dates=None, write_index=True,
18561856
data_label=None, variable_labels=None, version=114,
18571857
convert_strl=None):
18581858
"""
1859-
Export Stata binary dta files.
1859+
Converting data frame object to Stata dta format.
1860+
1861+
Writes the Dataframe to a Stata dataset file.
1862+
"dta" files contain a Stata dataset.
18601863
18611864
Parameters
18621865
----------
18631866
fname : path (string), buffer or path object
1864-
string, path object (pathlib.Path or py._path.local.LocalPath) or
1867+
String, path object (pathlib.Path or py._path.local.LocalPath) or
18651868
object implementing a binary write() functions. If using a buffer
18661869
then the buffer will not be automatically closed after the file
18671870
data has been written.
@@ -1921,27 +1924,27 @@ def to_stata(self, fname, convert_dates=None, write_index=True,
19211924
19221925
See Also
19231926
--------
1924-
pandas.read_stata : Import Stata data files.
1925-
pandas.io.stata.StataWriter : Low-level writer for Stata data files.
1926-
pandas.io.stata.StataWriter117 : Low-level writer for version 117
1927-
files.
1927+
read_stata : Import Stata data files.
1928+
io.stata.StataWriter : Low-level writer for Stata data files.
1929+
io.stata.StataWriter117 : Low-level writer for version 117 files.
19281930
19291931
Examples
19301932
--------
1931-
>>> data.to_stata('./data_file.dta')
1932-
1933-
Or with dates
1933+
Converting dataframe with date column to Stata dta file
1934+
using the to_stata method.
19341935
1935-
>>> data.to_stata('./date_data_file.dta', {2 : 'tw'})
1936+
>>> dates = pd.date_range(start='2018-01-01', periods=4)
1937+
>>> df = pd.DataFrame({'date': dates,
1938+
... 'animal': ['falcon', 'parrot', 'falcon',
1939+
... 'parrot'],
1940+
... 'speed': [350, 18, 361, 15]}).set_index(['date',
1941+
... 'animal'])
1942+
>>> df.to_stata('animals.dta')
19361943
19371944
Alternatively you can create an instance of the StataWriter class
19381945
1939-
>>> writer = StataWriter('./data_file.dta', data)
1940-
>>> writer.write_file()
1941-
1942-
With dates:
1943-
1944-
>>> writer = StataWriter('./date_data_file.dta', data, {2 : 'tw'})
1946+
>>> StataWriter = pd.io.stata.StataWriter
1947+
>>> writer = StataWriter('animals.dta', df)
19451948
>>> writer.write_file()
19461949
"""
19471950
kwargs = {}

0 commit comments

Comments
 (0)