@@ -1326,6 +1326,8 @@ def parse(self, sheetname, header=0, skiprows=None, skip_footer=0,
1326
1326
If None then parse all columns,
1327
1327
If int then indicates last column to be parsed
1328
1328
If list of ints then indicates list of column numbers to be parsed
1329
+ If string then indicates comma separated list of column names and
1330
+ column ranges (e.g. "A:E" or "A,C,E:F")
1329
1331
na_values : list-like, default None
1330
1332
List of additional strings to recognize as NA/NaN
1331
1333
@@ -1350,8 +1352,34 @@ def parse(self, sheetname, header=0, skiprows=None, skip_footer=0,
1350
1352
skip_footer = skip_footer )
1351
1353
1352
1354
def _should_parse (self , i , parse_cols ):
1355
+
1356
+ def _range2cols (areas ):
1357
+ """
1358
+ Convert comma separated list of column names and column ranges to a
1359
+ list of 0-based column indexes.
1360
+
1361
+ >>> _range2cols('A:E')
1362
+ [0, 1, 2, 3, 4]
1363
+ >>> _range2cols('A,C,Z:AB')
1364
+ [0, 2, 25, 26, 27]
1365
+ """
1366
+ def _excel2num (x ):
1367
+ "Convert Excel column name like 'AB' to 0-based column index"
1368
+ return reduce (lambda s ,a : s * 26 + ord (a )- ord ('A' )+ 1 , x .upper ().strip (), 0 )- 1
1369
+
1370
+ cols = []
1371
+ for rng in areas .split (',' ):
1372
+ if ':' in rng :
1373
+ rng = rng .split (':' )
1374
+ cols += range (_excel2num (rng [0 ]), _excel2num (rng [1 ])+ 1 )
1375
+ else :
1376
+ cols .append (_excel2num (rng ))
1377
+ return cols
1378
+
1353
1379
if isinstance (parse_cols , int ):
1354
1380
return i <= parse_cols
1381
+ if isinstance (parse_cols , basestring ):
1382
+ return i in _range2cols (parse_cols )
1355
1383
else :
1356
1384
return i in parse_cols
1357
1385
0 commit comments