Question

Actually i am reading an Excel sheet using python i know how to slice the rows based on no's,but what i want is to slice row values based on row values... For example:

       col1  col2  col3
      ---------------
row1 | sss   2     3
row2 | ppp   4     5
row3 | vvv   6     7

I need to slice row but using row values like slice(col0,sss,vvv) like this i want.so that if any row order changes also i can access that row values based on name.

I dont need like this slice(0,4,6)...pls help me thanks in advance

Was it helpful?

Solution

so that if any row order changes also i can access that row values based on name.

Based on that fragment and the diagram, you possibly want something like this (untested):

rd = {}
for rowx in xrange(1, sheet.nrows):
    cell = sheet.cell(rowx, 0)
    if cell.ctype != xlrd.XL_CELL_TEXT: continue
    cv = cell.value.strip()
    if not cv: continue
    if cv in rd:
        complain_about_duplicate_row_names()
    rd[cv] = sheet.row_values(rowx)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top