Reads observations from Stata file, converting them into a dataframe Parameters ---------- nrows : int Number of lines to read from data file, if None read whole file. convert_dates : bool, default True Convert date variables to DataF
(
self,
nrows: int | None = None,
convert_dates: bool | None = None,
convert_categoricals: bool | None = None,
index_col: str | None = None,
convert_missing: bool | None = None,
preserve_dtypes: bool | None = None,
columns: Sequence[str] | None = None,
order_categoricals: bool | None = None,
)
| 1599 | return self.read(nrows=size) |
| 1600 | |
| 1601 | def read( |
| 1602 | self, |
| 1603 | nrows: int | None = None, |
| 1604 | convert_dates: bool | None = None, |
| 1605 | convert_categoricals: bool | None = None, |
| 1606 | index_col: str | None = None, |
| 1607 | convert_missing: bool | None = None, |
| 1608 | preserve_dtypes: bool | None = None, |
| 1609 | columns: Sequence[str] | None = None, |
| 1610 | order_categoricals: bool | None = None, |
| 1611 | ) -> DataFrame: |
| 1612 | """ |
| 1613 | Reads observations from Stata file, converting them into a dataframe |
| 1614 | |
| 1615 | Parameters |
| 1616 | ---------- |
| 1617 | nrows : int |
| 1618 | Number of lines to read from data file, if None read whole file. |
| 1619 | convert_dates : bool, default True |
| 1620 | Convert date variables to DataFrame time values. |
| 1621 | convert_categoricals : bool, default True |
| 1622 | Read value labels and convert columns to Categorical/Factor variables. |
| 1623 | index_col : str, optional |
| 1624 | Column to set as index. |
| 1625 | convert_missing : bool, default False |
| 1626 | Flag indicating whether to convert missing values to their Stata |
| 1627 | representations. If False, missing values are replaced with nan. |
| 1628 | If True, columns containing missing values are returned with |
| 1629 | object data types and missing values are represented by |
| 1630 | StataMissingValue objects. |
| 1631 | preserve_dtypes : bool, default True |
| 1632 | Preserve Stata datatypes. If False, numeric data are upcast to pandas |
| 1633 | default types for foreign data (float64 or int64). |
| 1634 | columns : list or None |
| 1635 | Columns to retain. Columns will be returned in the given order. None |
| 1636 | returns all columns. |
| 1637 | order_categoricals : bool, default True |
| 1638 | Flag indicating whether converted categorical data are ordered. |
| 1639 | |
| 1640 | Returns |
| 1641 | ------- |
| 1642 | DataFrame |
| 1643 | """ |
| 1644 | self._ensure_open() |
| 1645 | |
| 1646 | # Handle options |
| 1647 | if convert_dates is None: |
| 1648 | convert_dates = self._convert_dates |
| 1649 | if convert_categoricals is None: |
| 1650 | convert_categoricals = self._convert_categoricals |
| 1651 | if convert_missing is None: |
| 1652 | convert_missing = self._convert_missing |
| 1653 | if preserve_dtypes is None: |
| 1654 | preserve_dtypes = self._preserve_dtypes |
| 1655 | if columns is None: |
| 1656 | columns = self._columns |
| 1657 | if order_categoricals is None: |
| 1658 | order_categoricals = self._order_categoricals |
no test coverage detected