Skip to content

Commit 9a71737

Browse files
committed
ENH: Added StataReader and StataWriter (#1512)
1 parent e82003f commit 9a71737

File tree

8 files changed

+1250
-0
lines changed

8 files changed

+1250
-0
lines changed

pandas/core/frame.py

+29
Original file line numberDiff line numberDiff line change
@@ -1280,6 +1280,35 @@ def from_csv(cls, path, header=0, sep=',', index_col=0,
12801280
parse_dates=parse_dates, index_col=index_col,
12811281
encoding=encoding)
12821282

1283+
@classmethod
1284+
def from_dta(dta, path, parse_dates=True, convert_categoricals=True, encoding=None, index_col=None):
1285+
"""
1286+
Read Stata file into DataFrame
1287+
1288+
Parameters
1289+
----------
1290+
path : string file path or file handle / StringIO
1291+
parse_dates : boolean, default True
1292+
Convert date variables to DataFrame time values
1293+
convert_categoricals : boolean, default True
1294+
Read value labels and convert columns to Categorical/Factor variables
1295+
encoding : string, None or encoding, default None
1296+
Encoding used to parse the files. Note that Stata doesn't
1297+
support unicode. None defaults to cp1252.
1298+
index_col : int or sequence, default None
1299+
Column to use for index. If a sequence is given, a MultiIndex
1300+
is used. Different default from read_table
1301+
1302+
Notes
1303+
-----
1304+
1305+
Returns
1306+
-------
1307+
y : DataFrame
1308+
"""
1309+
from pandas.io.parsers import read_stata
1310+
return read_stata(path, parse_dates=parse_dates, convert_categoricals=convert_categoricals, encoding=encoding, index=index_col)
1311+
12831312
def to_sparse(self, fill_value=None, kind='block'):
12841313
"""
12851314
Convert to SparseDataFrame

0 commit comments

Comments
 (0)