954,515 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Python assignment

if a file that has multiple columns, like

1 7 3 8 5 6 
      3 4 5 6 7 8
      1 7 6 4 4 3



i want to read the first row and see if there numbers that are grater than 6. Then add that number to all the number in that column. For Example, for the second column i want to take 7 and add it to 7, 4, and 7. i can read the values and identify which number are grater than 6, but idk how i can add that number the specific column. Please Help!

import xlrd
import os

folder = "data"
dirList=os.listdir(path)

for file in dirList:
        fullpath = os.path.join(folder,file)
        if os.path.isfile(fullpath) == 1:
                wb = xlrd.open_workbook(fullpath)
                sh = wb.sheet_by_index(0)
                for i in range(0, 1):
##                    print sh.row_values(i)
                    for values in sh.row_values(i):
                        if values > 6:
##                            print values
##                            print len(sh.col_values(0))
g_amanu
Newbie Poster
24 posts since Aug 2011
Reputation Points: 10
Solved Threads: 0
 

Collect tuples of column index, value from columns with required value.

pyTony
pyMod
Moderator
5,359 posts since Apr 2010
Reputation Points: 782
Solved Threads: 852
 


A way that is perhaps easier to understand, but slightly more processor intensive, is to store the first record, add up all of the columns from all of the records, and then print the values for the columns > 6 in the first record. And I don't understand what the variable "idk" is used for.

woooee
Nearly a Posting Maven
2,454 posts since Dec 2006
Reputation Points: 777
Solved Threads: 714
 

'idk' means i dont know.

pyTony--i have multiple files. And one file might have a number grater than 6 in the first column, but the other files might have a number grater than 6 in the third column. so i cant specifically tell it the fist column or the third column or.....

g_amanu
Newbie Poster
24 posts since Aug 2011
Reputation Points: 10
Solved Threads: 0
 

Of course, the values of columns must be collected from first row in each file, logical thing would be to make function for processing and calling it with each file as argument. You allready told that before.

pyTony
pyMod
Moderator
5,359 posts since Apr 2010
Reputation Points: 782
Solved Threads: 852
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: