3131import pandas .compat .openpyxl_compat as openpyxl_compat
3232from warnings import warn
3333from distutils .version import LooseVersion
34- from pandas .util ._decorators import Appender
34+ from pandas .util ._decorators import Appender , deprecate_kwarg
3535from textwrap import fill
3636
3737__all__ = ["read_excel" , "ExcelWriter" , "ExcelFile" ]
8686 Column (0-indexed) to use as the row labels of the DataFrame.
8787 Pass None if there is no such column. If a list is passed,
8888 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
9090 is based on the subset.
9191names : array-like, default None
9292 List of column names to use. If file contains no header row,
115115 .. versionadded:: 0.19.0
116116
117117parse_cols : int or list, default None
118+ .. deprecated:: 0.21.0
119+ Pass in `usecols` instead.
120+
121+ usecols : int or list, default None
118122 * If None then parse all columns,
119123 * If int then indicates last column to be parsed
120124 * If list of ints then indicates list of column numbers to be parsed
@@ -205,8 +209,9 @@ def get_writer(engine_name):
205209
206210
207211@Appender (_read_excel_doc )
212+ @deprecate_kwarg ("parse_cols" , "usecols" )
208213def 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 ,
210215 date_parser = None , na_values = None , thousands = None ,
211216 convert_float = True , converters = None , dtype = None ,
212217 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,
226231
227232 return io ._parse_excel (
228233 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 ,
230235 date_parser = date_parser , na_values = na_values , thousands = thousands ,
231236 convert_float = convert_float , skip_footer = skip_footer ,
232237 converters = converters , dtype = dtype , true_values = true_values ,
@@ -295,7 +300,7 @@ def __fspath__(self):
295300 return self ._io
296301
297302 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 ,
299304 date_parser = None , na_values = None , thousands = None ,
300305 convert_float = True , converters = None , true_values = None ,
301306 false_values = None , squeeze = False , ** kwds ):
@@ -309,7 +314,7 @@ def parse(self, sheet_name=0, header=0, skiprows=None, skip_footer=0,
309314 return self ._parse_excel (sheetname = sheet_name , header = header ,
310315 skiprows = skiprows , names = names ,
311316 index_col = index_col ,
312- parse_cols = parse_cols ,
317+ usecols = usecols ,
313318 parse_dates = parse_dates ,
314319 date_parser = date_parser , na_values = na_values ,
315320 thousands = thousands ,
@@ -321,7 +326,7 @@ def parse(self, sheet_name=0, header=0, skiprows=None, skip_footer=0,
321326 squeeze = squeeze ,
322327 ** kwds )
323328
324- def _should_parse (self , i , parse_cols ):
329+ def _should_parse (self , i , usecols ):
325330
326331 def _range2cols (areas ):
327332 """
@@ -347,15 +352,15 @@ def _excel2num(x):
347352 cols .append (_excel2num (rng ))
348353 return cols
349354
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 )
354359 else :
355- return i in parse_cols
360+ return i in usecols
356361
357362 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 ,
359364 parse_dates = False , date_parser = None , na_values = None ,
360365 thousands = None , convert_float = True , true_values = None ,
361366 false_values = None , verbose = False , dtype = None ,
@@ -470,10 +475,10 @@ def _parse_cell(cell_contents, cell_typ):
470475 row = []
471476 for j , (value , typ ) in enumerate (zip (sheet .row_values (i ),
472477 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 )
475480
476- if parse_cols is None or should_parse [j ]:
481+ if usecols is None or should_parse [j ]:
477482 row .append (_parse_cell (value , typ ))
478483 data .append (row )
479484
0 commit comments