1

I'm trying to

  • loop over multiple csv files,

  • extract information from them

  • write an output into one new csv file with a row for each of the original files.

I take the information:

Name, Date, Time, Test, Navg, Percent

for each row.

I have tried to do it, however I have the problems:

  1. It writes each of Name, Date, Time, Test, Navg, Percent to a NEW ROW...I want each word in a new column
  2. It writes each new file to the a new row underneath(I do want it underneath, but with each word in a column.

    b = open('C:\Users\AClayton\Desktop\Data.csv', 'a')
    a = csv.writer(b,delimiter='\t',lineterminator='\n')
    a.writerows((Name, Date, Time, Test, Navg, Percent))
    b.close()
    

Note the file has been read and the data extracted in earlier code.

2
  • Please don't add text like "[Python]" to your question's title - tagging the question correctly is sufficient. Commented Sep 10, 2013 at 9:24
  • You need writerow() instead of writerows(). Commented Sep 10, 2013 at 9:25

1 Answer 1

1

writerows interpretes the input argument as a list of rows, hence each item in your tuple is written into a separate row. Using writerow should write it into a single row.

Sign up to request clarification or add additional context in comments.

2 Comments

thanks, Sebastian, it's half way there. However, I would like to put each in a new cell in the csv. At the moment it is all in one cell
ahh changed the delimiter to a comma and it worked perfectly :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.