2

Is it possible to write a csv cell by mentioning its row and column number. I'm aware of python 'csv' module in which 'csv.writer' has only writerow and writerows method to write data. These methods always writes the data in a new row, but i want to write it in a single row different columns in one run. Problem is i cant accumulate data in a list and write it at once, I have to do some action and get data, to write it to the next column

For example I have to open csv and start with a new row, write some data in the first column, perform some action get the data and write it to the second column, likewise i have to write many columns

As mentioned above I've tried it using csv.writer's writerow and writecolumn methods and couldn't accomplish this. Anyone had come across similar thing, kindly let me know how can i accomplish this.

1 Answer 1

3

Well, if you are filling columns one by one, from left to right - use normal file.write(), separated by coma :)

example:

f = open('test.csv', 'w')
f.write('ab,')

# do something

#write data to next column
f.write('ab,')

It will produce test.csv with first row: ab,ab

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

2 Comments

and what about writing to a different row?
Well, in csv next row is simply next line in file. But if you want to do more complex works on csv's, I'd suggest you to try pandas.pydata.org/pandas-docs/stable/generated/…

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.