Edit/Append data to csv file

hello all,

I am having this problem that I am not sure how to solve.
is this a good place to post it?

the csv file as is:

col1,col2,col3,col4,col5

value1,value2,value3,value4,value5

,,value6,value7,value8,value9

,,value10,value11,value12,value13`

the expected csv file after the function runs:

Note: the function will be inside a loop, so the parameters will be passed to it each time the loop gets executed, therefore param 1 and 2 are written in the file as the loop executes for the first time.

`

col1,col2,col3,col4,col5

value1,value2,value3,value4,value5

argument1,argumen2,value6,value7,value8,value9

argument3,argument4,value10,value11,value12,value13

with this function I get the arguments passed on a new line and not inside the empty cells

def append_value(file, *argv):
    my_file = open(file, 'a')
    my_line = ','.join([argv]) + '\n'
    my_file.write(my_line)
    my_file.close()

could I get some help, please?
I think using with, to open would be better?

Is there another way to edit this csv file without using pandas?

Yeah, check csv module.
Also tutorial1, tutorial2 on python and csv.

1 Like

when you checked them tutorials what that told you?

They told me how to manipulate csv files using python.

Last part on tutorialspoint.com may be answer to your question.

1 Like

You can flag my post, though.

I read your badly written post, answered your question, even linked some tutorials for further reading.
I even mentioned where is the part that interests you - in the last section of the tutorial on tutorialspoint…

Nice way of saying ‘thanks’. I’m out of this thread.

1 Like

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.