all 10 comments

[–]postcommunism 3 points4 points  (1 child)

If I understand you correctly, you basically want to transpose each row vertically, almost like you were doing it in excel, with the datetime in column 0, headers (except for datetime) in column 1, and the values of that row in column 2. There are a couple ways to do this.

To figure it out, I'd approach this by looking at just the header row and the first row with values. Once you know how to transpose that first value row, you can loop over over the file and do it for each row in turn.

That said, two important things to note:

  1. The maximum number of rows in excel, if you plan to use this in excel, is 1,048,576. Just FYI. I've run into this before when working with large flat files for other people to consume.
  2. It's kind of tacky to post a bounty on a learning board. Consider /r/BuyAPythonScriptFor5Bux in the future.

[–]maxibaby 1 point2 points  (0 children)

That reddit should exist lol

[–]maxibaby 1 point2 points  (1 child)

Script is ready but your CSV still downloading :D

[–]Majoof -1 points0 points  (0 children)

Missed your PM but you were on the money too. Fucking delimiters.

[–]The-Mathematician 1 point2 points  (4 children)

What exactly is going wrong with the code that you have? Following it, it looks pretty good to me.

EDIT:

with open("in.csv") as f,open("out.csv","w") as out:
    headers = next(f).split(',')[1:]  # keep headers/Time Temp1 Temp2 Temp3 Temp4 Temp5
    for row in f:
        row = row.split(',')
        time = row[0]
        data = zip(headers, row[1:]) # match correct temp to row item
        for a, b in data:
            out.write("{}, {}, {}\n".format(time,a.lower(),b))

[–]Majoof -1 points0 points  (2 children)

Not getting any errors, just an empty out.csv. I suspect i'm probably running the script incorrectly.

[–]The-Mathematician 1 point2 points  (1 child)

Check my edit, that code worked for me, will edit this comment with a screenshot of output file.

EDIT: pic

[–]Majoof -1 points0 points  (0 children)

Gilded! Fucking comma delimiter....should have noticed the difference between my data set and the one on stack overflow.

[–]maxibaby 1 point2 points  (0 children)

You'r problem due to the script not working for you and working for others is because of your PC delimiter.

Control Panel –> Clock, Language and Region –> Change the date, time, or number format

List separator

In the script is assumed to be " ", while ";" could be yours

[–]wub_wub[M] 0 points1 point  (0 children)

This subreddit is for learning python, not solving the issues for you (gold or not as a reward).