pandas.api.typing.StataReader.read#
- StataReader.read(
- nrows=None,
- convert_dates=None,
- convert_categoricals=None,
- index_col=None,
- convert_missing=None,
- preserve_dtypes=None,
- columns=None,
- order_categoricals=None,
Read observations from the Stata file into a DataFrame.
Options other than
nrowsleft as None fall back to the values given when the reader was created.- Parameters:
- nrowsint, optional
Number of lines to read from data file, if None read the rest of the file.
- convert_datesbool, optional
Convert date variables to DataFrame time values.
- convert_categoricalsbool, optional
Read value labels and convert columns to Categorical/Factor variables.
- index_colstr, optional
Column to set as index.
- convert_missingbool, optional
Flag indicating whether to convert missing values to their Stata representations. If False, missing values are replaced with nan. If True, columns containing missing values are returned with object data types and missing values are represented by StataMissingValue objects.
- preserve_dtypesbool, optional
Preserve Stata datatypes. If False, numeric data are upcast to pandas default types for foreign data (float64 or int64).
- columnslist, optional
Columns to retain. Columns will be returned in the given order.
- order_categoricalsbool, optional
Flag indicating whether converted categorical data are ordered.
- Returns:
- DataFrame
The observations read.
See also
read_stataRead Stata file into DataFrame.
Examples
>>> from io import BytesIO >>> buf = BytesIO() >>> pd.DataFrame({"a": [1, 2, 3]}).to_stata(buf, write_index=False) >>> _ = buf.seek(0) >>> with pd.read_stata(buf, iterator=True) as reader: ... reader.read(2) a 0 1 1 2