137
137
na_values : scalar, str, list-like, or dict, default None
138
138
Additional strings to recognize as NA/NaN. If dict passed, specific
139
139
per-column NA values. By default the following values are interpreted
140
- as NaN: '""" + fill ("', '" .join (sorted (_NA_VALUES )), 70 ) + """'.
140
+ as NaN: '""" + fill ("', '" .join (sorted (_NA_VALUES )), 70 , subsequent_indent = " " ) + """'.
141
141
keep_default_na : bool, default True
142
142
If na_values are specified and keep_default_na is False the default NaN
143
143
values are overridden, otherwise they're appended to.
148
148
this parameter is only necessary for columns stored as TEXT in Excel,
149
149
any numeric columns will automatically be parsed, regardless of display
150
150
format.
151
+ comment : str, default None
152
+ Comments out remainder of line. Pass a character or characters to this
153
+ argument to indicate comments in the input file. Any data between the
154
+ comment string and the end of the current line is ignored.
151
155
skip_footer : int, default 0
152
156
153
157
.. deprecated:: 0.23.0
164
168
parsed : DataFrame or Dict of DataFrames
165
169
DataFrame from the passed in Excel file. See notes in sheet_name
166
170
argument for more information on when a Dict of Dataframes is returned.
171
+
172
+ Examples
173
+ --------
174
+
175
+ An example DataFrame written to a local file
176
+
177
+ >>> df_out = pd.DataFrame([('string1', 1),
178
+ ... ('string2', 2),
179
+ ... ('string3', 3)],
180
+ ... columns=['Name', 'Value'])
181
+ >>> df_out
182
+ Name Value
183
+ 0 string1 1
184
+ 1 string2 2
185
+ 2 string3 3
186
+ >>> df_out.to_excel('tmp.xlsx')
187
+
188
+ The file can be read using the file name as string or an open file object:
189
+
190
+ >>> pd.read_excel('tmp.xlsx')
191
+ Name Value
192
+ 0 string1 1
193
+ 1 string2 2
194
+ 2 string3 3
195
+
196
+ >>> pd.read_excel(open('tmp.xlsx','rb'))
197
+ Name Value
198
+ 0 string1 1
199
+ 1 string2 2
200
+ 2 string3 3
201
+
202
+ Index and header can be specified via the `index_col` and `header` arguments
203
+
204
+ >>> pd.read_excel('tmp.xlsx', index_col=None, header=None)
205
+ 0 1 2
206
+ 0 NaN Name Value
207
+ 1 0.0 string1 1
208
+ 2 1.0 string2 2
209
+ 3 2.0 string3 3
210
+
211
+ Column types are inferred but can be explicitly specified
212
+
213
+ >>> pd.read_excel('tmp.xlsx', dtype={'Name':str, 'Value':float})
214
+ Name Value
215
+ 0 string1 1.0
216
+ 1 string2 2.0
217
+ 2 string3 3.0
218
+
219
+ True, False, and NA values, and thousands separators have defaults,
220
+ but can be explicitly specified, too. Supply the values you would like
221
+ as strings or lists of strings!
222
+
223
+ >>> pd.read_excel('tmp.xlsx',
224
+ ... na_values=['string1', 'string2'])
225
+ Name Value
226
+ 0 NaN 1
227
+ 1 NaN 2
228
+ 2 string3 3
229
+
230
+ Comment lines in the excel input file can be skipped using the `comment` kwarg
231
+
232
+ >>> df = pd.DataFrame({'a': ['1', '#2'], 'b': ['2', '3']})
233
+ >>> df.to_excel('tmp.xlsx', index=False)
234
+ >>> pd.read_excel('tmp.xlsx')
235
+ a b
236
+ 0 1 2
237
+ 1 #2 3
238
+
239
+ >>> pd.read_excel('tmp.xlsx', comment='#')
240
+ a b
241
+ 0 1 2
167
242
"""
168
243
169
244
@@ -223,6 +298,7 @@ def read_excel(io,
223
298
parse_dates = False ,
224
299
date_parser = None ,
225
300
thousands = None ,
301
+ comment = None ,
226
302
skipfooter = 0 ,
227
303
convert_float = True ,
228
304
** kwds ):
@@ -256,6 +332,7 @@ def read_excel(io,
256
332
parse_dates = parse_dates ,
257
333
date_parser = date_parser ,
258
334
thousands = thousands ,
335
+ comment = comment ,
259
336
skipfooter = skipfooter ,
260
337
convert_float = convert_float ,
261
338
** kwds )
@@ -338,6 +415,7 @@ def parse(self,
338
415
parse_dates = False ,
339
416
date_parser = None ,
340
417
thousands = None ,
418
+ comment = None ,
341
419
skipfooter = 0 ,
342
420
convert_float = True ,
343
421
** kwds ):
@@ -363,6 +441,7 @@ def parse(self,
363
441
parse_dates = parse_dates ,
364
442
date_parser = date_parser ,
365
443
thousands = thousands ,
444
+ comment = comment ,
366
445
skipfooter = skipfooter ,
367
446
convert_float = convert_float ,
368
447
** kwds )
@@ -417,6 +496,7 @@ def _parse_excel(self,
417
496
parse_dates = False ,
418
497
date_parser = None ,
419
498
thousands = None ,
499
+ comment = None ,
420
500
skipfooter = 0 ,
421
501
convert_float = True ,
422
502
** kwds ):
@@ -591,6 +671,7 @@ def _parse_cell(cell_contents, cell_typ):
591
671
parse_dates = parse_dates ,
592
672
date_parser = date_parser ,
593
673
thousands = thousands ,
674
+ comment = comment ,
594
675
skipfooter = skipfooter ,
595
676
** kwds )
596
677
0 commit comments