I'm just started to learn about python and i did not have programing
language experience before.
I am trying to work with some excel files and I wonder if you could
help me with this.
my infile looks like this:
NAME STATUS NY EF REG LAM CRI KRU
RC1 PRESENT AA BB BB BB BB BB
RC2 MM MM MM MM MM MM
RC3 PRESENT AA AA AB AB BB AA
RC4 PRESENT BB AA AA AB AB AA
I am trying to do several things with this data set but basically I am
trying to reformat the data in this way:
NAME STATUS
RC1 PRESENT NY AA
RC1 PRESENT EF BB
RC1 PRESENT REG BB
RC1 PRESENT LAM BB
RC1 PRESENT CRI BB
RC1 PRESENT KRU BB
RC3 PRESENT NY AA
RC3 PRESENT EF AA
RC3 PRESENT REG AB
RC3 PRESENT LAM AB
RC3 PRESENT CRI BB
RC3 PRESENT KRU AA
RC4 PRESENT NY BB
RC4 PRESENT EF AA
RC4 PRESENT REG AA
RC4 PRESENT LAM AB
RC4 PRESENT CRI AB
RC4 PRESENT KRU AA
the condition is that if status exist (i.e. present is as value), I
want to copy the name ( i.e.RC1) six times (in six rows).
once that occurred I wanted to transpose the headings of the names
(NY, EF, REG, LAM, CRI and KRU) and the values for each of them.
As I said , I am very new and i have just being able to select for
the values that are present bu not able to repeat the operation six
times:
Expand|Select|Wrap|Line Numbers
- import xlrd
- import xlwt
- import re
- book = xlrd.open_workbook('Book5.xls')
- sh1 = book.sheet_by_index(0)
- wb = xlwt.Workbook()
- ws = wb.add_sheet('A Test Sheet')
- idx=0
- for rx1 in range(sh1.nrows):
- if sh1.row(rx1)[10].value:
- print (sh1.cell_value(rx1,0))
- ws.write (idx, 0, sh1.row(rx1)[0].value)
- idx = idx + 1
- wb.save('out5.xls')
Thank you very much, any help would be really appreciated!!