MCPcopy
hub / github.com/pandas-dev/pandas / read_stata

Function read_stata

pandas/io/stata.py:2090–2236  ·  view source on GitHub ↗

Read Stata file into DataFrame. Parameters ---------- filepath_or_buffer : str, path object or file-like object Any valid string path is acceptable. The string could be a URL. Valid URL schemes include http, ftp, s3, and file. For file URLs, a host is expect

(
    filepath_or_buffer: FilePath | ReadBuffer[bytes],
    *,
    convert_dates: bool = True,
    convert_categoricals: bool = True,
    index_col: str | None = None,
    convert_missing: bool = False,
    preserve_dtypes: bool = True,
    columns: Sequence[str] | None = None,
    order_categoricals: bool = True,
    chunksize: int | None = None,
    iterator: bool = False,
    compression: CompressionOptions = "infer",
    storage_options: StorageOptions | None = None,
)

Source from the content-addressed store, hash-verified

2088
2089@set_module("pandas")
2090def read_stata(
2091 filepath_or_buffer: FilePath | ReadBuffer[bytes],
2092 *,
2093 convert_dates: bool = True,
2094 convert_categoricals: bool = True,
2095 index_col: str | None = None,
2096 convert_missing: bool = False,
2097 preserve_dtypes: bool = True,
2098 columns: Sequence[str] | None = None,
2099 order_categoricals: bool = True,
2100 chunksize: int | None = None,
2101 iterator: bool = False,
2102 compression: CompressionOptions = "infer",
2103 storage_options: StorageOptions | None = None,
2104) -> DataFrame | StataReader:
2105 """
2106 Read Stata file into DataFrame.
2107
2108 Parameters
2109 ----------
2110 filepath_or_buffer : str, path object or file-like object
2111 Any valid string path is acceptable. The string could be a URL. Valid
2112 URL schemes include http, ftp, s3, and file. For file URLs, a host is
2113 expected. A local file could be: ``file://localhost/path/to/table.dta``.
2114
2115 If you want to pass in a path object, pandas accepts any ``os.PathLike``.
2116
2117 By file-like object, we refer to objects with a ``read()`` method,
2118 such as a file handle (e.g. via builtin ``open`` function)
2119 or ``StringIO``.
2120 convert_dates : bool, default True
2121 Convert date variables to DataFrame time values.
2122 convert_categoricals : bool, default True
2123 Read value labels and convert columns to Categorical/Factor variables.
2124 index_col : str, optional
2125 Column to set as index.
2126 convert_missing : bool, default False
2127 Flag indicating whether to convert missing values to their Stata
2128 representations. If False, missing values are replaced with nan.
2129 If True, columns containing missing values are returned with
2130 object data types and missing values are represented by
2131 StataMissingValue objects.
2132 preserve_dtypes : bool, default True
2133 Preserve Stata datatypes. If False, numeric data are upcast to pandas
2134 default types for foreign data (float64 or int64).
2135 columns : list or None
2136 Columns to retain. Columns will be returned in the given order. None
2137 returns all columns.
2138 order_categoricals : bool, default True
2139 Flag indicating whether converted categorical data are ordered.
2140 chunksize : int, default None
2141 Return StataReader object for iterations, returns chunks with
2142 given number of lines.
2143 iterator : bool, default False
2144 Return StataReader object.
2145 compression : str or dict, default 'infer'
2146 For on-the-fly decompression of on-disk data. If 'infer' and
2147 'filepath_or_buffer' is path-like, then detect compression from the

Callers 15

time_read_stataMethod · 0.90
parsed_114Function · 0.90
read_dtaMethod · 0.90
test_read_empty_dtaMethod · 0.90
test_encodingMethod · 0.90
test_105Method · 0.90
test_big_datesMethod · 0.90

Calls 2

readMethod · 0.95
StataReaderClass · 0.85

Tested by 15

parsed_114Function · 0.72
read_dtaMethod · 0.72
test_read_empty_dtaMethod · 0.72
test_encodingMethod · 0.72
test_105Method · 0.72
test_big_datesMethod · 0.72
test_dtype_conversionMethod · 0.72