473,326 Members | 2,175 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

excel in python

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
0 1514

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

Similar topics

13
by: Allison Bailey | last post by:
Hi Folks, I'm a brand new Python programmer, so please point me in the right direction if this is not the best forum for this question.... I would like to open an existing MS Excel spreadsheet...
12
by: rhmd | last post by:
Just found Python and I love it. What an elegant language! I would like to use it for various applications, but the mathematical calculations are way too slow (a million sines 8 seconds in Python...
4
by: Marc | last post by:
Hi all, I am trying to write an application where I need the ability to open an Excel spreadsheet and do basic read/write, insert rows, and hide/unhide rows. Using win32com I have been able to...
5
by: Bram Stolk | last post by:
pyHello, Google helped me find a nice package to interface python with MS Excel. "win32all", or sometimes called by the name "pywin32". http://starship.python.net/crew/mhammond/ However,...
2
by: Kevin T. Ryan | last post by:
Hi Group - I have written a "semi-program" in MS Excel related to running a football pool. I've updated it over the past two years or so, to the point where it is getting pretty advanced. ...
3
by: Xiao-Qin Xia | last post by:
I don't like VBA, and want to use python to work with Excel. Does anybody recommend some good documents to begin with? Many thanks, Xiao-Qin
14
by: Rochester | last post by:
Hi, I just found out that the general open file mechanism doesn't work for named pipes (fifo). Say I wrote something like this and it simply hangs python: #!/usr/bin/python import os
2
by: John Henry | last post by:
I posted the following message to the Pywin32 list but if anybody here can help, it would be appreciated very much. ============================ Hi list, I have a need to copy 3 rows of data...
6
by: AleydisGP | last post by:
I have a .plt file (which is a tab delimited ASCII file) and I want to format it to get a .dbf with data in rows and columns, detele some rows/columns and substitute decimal '.' with ','. All this...
15
by: patf | last post by:
Hi - experienced programmer but this is my first Python program. This URL will retrieve an excel spreadsheet containing (that day's) msci stock index returns. ...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.