By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,814 Members | 1,111 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,814 IT Pros & Developers. It's quick & easy.

excel in python

P: 1
Hi,
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
  1. import xlrd
  2. import xlwt
  3. import re
  4.  
  5. book = xlrd.open_workbook('Book5.xls')
  6. sh1 = book.sheet_by_index(0)
  7. wb = xlwt.Workbook()
  8. ws = wb.add_sheet('A Test Sheet')
  9. idx=0
  10. for rx1 in range(sh1.nrows):
  11.    if sh1.row(rx1)[10].value:
  12.        print (sh1.cell_value(rx1,0))
  13.        ws.write (idx, 0, sh1.row(rx1)[0].value)
  14.        idx = idx + 1
  15. wb.save('out5.xls')
what else can I do to the rest???
Thank you very much, any help would be really appreciated!!
Sep 22 '11 #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.