Urgent python help

Hi, I have a python assignment due in about 3 hours, and naturally, like every uni student, I’ve left it to the last minute. The problem is, I need to take tables provided as test data, and retrieve the values, and then make graphs. I’m having problems retrieving the values.

I wanted to do a nested for loop, something like this

For line in file(fileName)

Dang it, pressed enter.

For line in file(fileName)
For (insert thing that separates spaces or something in the line here)
Then store the values

Please help, it's urgent.

Assuming the data is stored in a file I would try this...

data_file= open("file", "r")
data_list = data_file.readlines()
data_file.close()

for item in data_list:
print item

Then you can do whatever to each element. But obviously I am just guessing and all the checks for file usage and other precautions is not there (just illustration), could you provide more detail?

won't that only read the lines? There's a number of values on each line. I know how to get the lines, but it's separating them into the separate values that's the problem.

I will upload the test data


that's the first test data


that's the next

aaand I just realised this is in the wrong section...

Ok I have not used csv before, but i can see that it was harder because of the return characters instead of new line ones for me. Some of the formatting has issues in the file. But i think you'll get the idea with this:

data_file= open("s.csv", "r")
data_list = []

data_list = data_file.readlines()
//print data_list[0]

mytext = ""
mytext = "\n".join(data_list[0].split("\r"))
new_list = mytext.split()

//line 6 is mixed up with column header
for i in range(7 ,len(new_list)):
test = new_list[i].split(",")
print test

And thats just using the stockbkp.csv, i renamed it to s for myself lol. Hope that helps

That helps a lot. I'll give that a go
Thanks man

How would I get the values out of that too? I need to make column graphs, so I need each line of values for each column

I would branch out again, and create a nested for loop to access test:

data_file= open("s.csv", "r")
data_list = []

data_list = data_file.readlines()
//print data_list[0]

mytext = ""
mytext = "\n".join(data_list[0].split("\r"))
new_list = mytext.split()

//line 6 is mixed up with column header
for i in range(7 ,len(new_list)):
test = new_list[i].split(",")
for j in range(len(test)):
print test[j]
print "\n"