31
31
import pandas .compat .openpyxl_compat as openpyxl_compat
32
32
from warnings import warn
33
33
from distutils .version import LooseVersion
34
- from pandas .util ._decorators import Appender
34
+ from pandas .util ._decorators import Appender , deprecate_kwarg
35
35
from textwrap import fill
36
36
37
37
__all__ = ["read_excel" , "ExcelWriter" , "ExcelFile" ]
86
86
Column (0-indexed) to use as the row labels of the DataFrame.
87
87
Pass None if there is no such column. If a list is passed,
88
88
those columns will be combined into a ``MultiIndex``. If a
89
- subset of data is selected with ``parse_cols ``, index_col
89
+ subset of data is selected with ``usecols ``, index_col
90
90
is based on the subset.
91
91
names : array-like, default None
92
92
List of column names to use. If file contains no header row,
115
115
.. versionadded:: 0.19.0
116
116
117
117
parse_cols : int or list, default None
118
+ .. deprecated:: 0.21.0
119
+ Pass in `usecols` instead.
120
+
121
+ usecols : int or list, default None
118
122
* If None then parse all columns,
119
123
* If int then indicates last column to be parsed
120
124
* If list of ints then indicates list of column numbers to be parsed
@@ -205,8 +209,9 @@ def get_writer(engine_name):
205
209
206
210
207
211
@Appender (_read_excel_doc )
212
+ @deprecate_kwarg ("parse_cols" , "usecols" )
208
213
def read_excel (io , sheet_name = 0 , header = 0 , skiprows = None , skip_footer = 0 ,
209
- index_col = None , names = None , parse_cols = None , parse_dates = False ,
214
+ index_col = None , names = None , usecols = None , parse_dates = False ,
210
215
date_parser = None , na_values = None , thousands = None ,
211
216
convert_float = True , converters = None , dtype = None ,
212
217
true_values = None , false_values = None , engine = None ,
@@ -226,7 +231,7 @@ def read_excel(io, sheet_name=0, header=0, skiprows=None, skip_footer=0,
226
231
227
232
return io ._parse_excel (
228
233
sheetname = sheet_name , header = header , skiprows = skiprows , names = names ,
229
- index_col = index_col , parse_cols = parse_cols , parse_dates = parse_dates ,
234
+ index_col = index_col , usecols = usecols , parse_dates = parse_dates ,
230
235
date_parser = date_parser , na_values = na_values , thousands = thousands ,
231
236
convert_float = convert_float , skip_footer = skip_footer ,
232
237
converters = converters , dtype = dtype , true_values = true_values ,
@@ -295,7 +300,7 @@ def __fspath__(self):
295
300
return self ._io
296
301
297
302
def parse (self , sheet_name = 0 , header = 0 , skiprows = None , skip_footer = 0 ,
298
- names = None , index_col = None , parse_cols = None , parse_dates = False ,
303
+ names = None , index_col = None , usecols = None , parse_dates = False ,
299
304
date_parser = None , na_values = None , thousands = None ,
300
305
convert_float = True , converters = None , true_values = None ,
301
306
false_values = None , squeeze = False , ** kwds ):
@@ -309,7 +314,7 @@ def parse(self, sheet_name=0, header=0, skiprows=None, skip_footer=0,
309
314
return self ._parse_excel (sheetname = sheet_name , header = header ,
310
315
skiprows = skiprows , names = names ,
311
316
index_col = index_col ,
312
- parse_cols = parse_cols ,
317
+ usecols = usecols ,
313
318
parse_dates = parse_dates ,
314
319
date_parser = date_parser , na_values = na_values ,
315
320
thousands = thousands ,
@@ -321,7 +326,7 @@ def parse(self, sheet_name=0, header=0, skiprows=None, skip_footer=0,
321
326
squeeze = squeeze ,
322
327
** kwds )
323
328
324
- def _should_parse (self , i , parse_cols ):
329
+ def _should_parse (self , i , usecols ):
325
330
326
331
def _range2cols (areas ):
327
332
"""
@@ -347,15 +352,15 @@ def _excel2num(x):
347
352
cols .append (_excel2num (rng ))
348
353
return cols
349
354
350
- if isinstance (parse_cols , int ):
351
- return i <= parse_cols
352
- elif isinstance (parse_cols , compat .string_types ):
353
- return i in _range2cols (parse_cols )
355
+ if isinstance (usecols , int ):
356
+ return i <= usecols
357
+ elif isinstance (usecols , compat .string_types ):
358
+ return i in _range2cols (usecols )
354
359
else :
355
- return i in parse_cols
360
+ return i in usecols
356
361
357
362
def _parse_excel (self , sheetname = 0 , header = 0 , skiprows = None , names = None ,
358
- skip_footer = 0 , index_col = None , parse_cols = None ,
363
+ skip_footer = 0 , index_col = None , usecols = None ,
359
364
parse_dates = False , date_parser = None , na_values = None ,
360
365
thousands = None , convert_float = True , true_values = None ,
361
366
false_values = None , verbose = False , dtype = None ,
@@ -470,10 +475,10 @@ def _parse_cell(cell_contents, cell_typ):
470
475
row = []
471
476
for j , (value , typ ) in enumerate (zip (sheet .row_values (i ),
472
477
sheet .row_types (i ))):
473
- if parse_cols is not None and j not in should_parse :
474
- should_parse [j ] = self ._should_parse (j , parse_cols )
478
+ if usecols is not None and j not in should_parse :
479
+ should_parse [j ] = self ._should_parse (j , usecols )
475
480
476
- if parse_cols is None or should_parse [j ]:
481
+ if usecols is None or should_parse [j ]:
477
482
row .append (_parse_cell (value , typ ))
478
483
data .append (row )
479
484
0 commit comments