|
126 | 126 | Return StataReader object for iterations, returns chunks with |
127 | 127 | given number of lines.""" |
128 | 128 |
|
129 | | -_iterator_params = """\ |
130 | | -iterator : bool, default False |
131 | | - Return StataReader object.""" |
132 | | - |
133 | 129 | _reader_notes = """\ |
134 | 130 | Notes |
135 | 131 | ----- |
|
138 | 134 | file is associated to an incomplete set of value labels that only |
139 | 135 | label a strict subset of the values.""" |
140 | 136 |
|
141 | | -_read_stata_doc = f""" |
142 | | -Read Stata file into DataFrame. |
143 | | -
|
144 | | -Parameters |
145 | | ----------- |
146 | | -filepath_or_buffer : str, path object or file-like object |
147 | | - Any valid string path is acceptable. The string could be a URL. Valid |
148 | | - URL schemes include http, ftp, s3, and file. For file URLs, a host is |
149 | | - expected. A local file could be: ``file://localhost/path/to/table.dta``. |
150 | | -
|
151 | | - If you want to pass in a path object, pandas accepts any ``os.PathLike``. |
152 | | -
|
153 | | - By file-like object, we refer to objects with a ``read()`` method, |
154 | | - such as a file handle (e.g. via builtin ``open`` function) |
155 | | - or ``StringIO``. |
156 | | -{_statafile_processing_params1} |
157 | | -{_statafile_processing_params2} |
158 | | -{_chunksize_params} |
159 | | -{_iterator_params} |
160 | | -{_shared_docs["decompression_options"] % "filepath_or_buffer"} |
161 | | -{_shared_docs["storage_options"]} |
162 | | -
|
163 | | -Returns |
164 | | -------- |
165 | | -DataFrame, pandas.api.typing.StataReader |
166 | | - If iterator or chunksize, returns StataReader, else DataFrame. |
167 | | -
|
168 | | -See Also |
169 | | --------- |
170 | | -io.stata.StataReader : Low-level reader for Stata data files. |
171 | | -DataFrame.to_stata: Export Stata data files. |
172 | | -
|
173 | | -{_reader_notes} |
174 | | -
|
175 | | -Examples |
176 | | --------- |
177 | | -
|
178 | | -Creating a dummy stata for this example |
179 | | -
|
180 | | ->>> df = pd.DataFrame({{'animal': ['falcon', 'parrot', 'falcon', 'parrot'], |
181 | | -... 'speed': [350, 18, 361, 15]}}) # doctest: +SKIP |
182 | | ->>> df.to_stata('animals.dta') # doctest: +SKIP |
183 | | -
|
184 | | -Read a Stata dta file: |
185 | | -
|
186 | | ->>> df = pd.read_stata('animals.dta') # doctest: +SKIP |
187 | | -
|
188 | | -Read a Stata dta file in 10,000 line chunks: |
189 | | -
|
190 | | ->>> values = np.random.randint(0, 10, size=(20_000, 1), dtype="uint8") # doctest: +SKIP |
191 | | ->>> df = pd.DataFrame(values, columns=["i"]) # doctest: +SKIP |
192 | | ->>> df.to_stata('filename.dta') # doctest: +SKIP |
193 | | -
|
194 | | ->>> with pd.read_stata('filename.dta', chunksize=10000) as itr: # doctest: +SKIP |
195 | | ->>> for chunk in itr: |
196 | | -... # Operate on a single chunk, e.g., chunk.mean() |
197 | | -... pass # doctest: +SKIP |
198 | | -""" |
199 | | - |
200 | | -_read_method_doc = f"""\ |
201 | | -Reads observations from Stata file, converting them into a dataframe |
202 | | -
|
203 | | -Parameters |
204 | | ----------- |
205 | | -nrows : int |
206 | | - Number of lines to read from data file, if None read whole file. |
207 | | -{_statafile_processing_params1} |
208 | | -{_statafile_processing_params2} |
209 | | -
|
210 | | -Returns |
211 | | -------- |
212 | | -DataFrame |
213 | | -""" |
214 | | - |
215 | 137 | _stata_reader_doc = f"""\ |
216 | 138 | Class for reading Stata dta files. |
217 | 139 |
|
|
0 commit comments