combining two csv files python -


i have data stored in 2 different csv files. want dump file b @ end of file , want remove header i.e, first line of file b. can combine 2 files using open('final.csv', 'a') includes header of file b. appreciated.

i'm assuming want know how skip header when reading file, since don't specify how 2 files appended (in-memory, on file system, ... ?).

after opening file, can use next() on file object skip ahead 1 line, so:

with open("file_b", "r") fb:     next(fb) # skip 1 line     line in fb:         # whatever want remaining lines, e.g. append them         # file_a 

alternatively, because had "numpy" question tag earlier, can use numpy's loadtxt() function, has parameter called skiprows can used want. open file_b so:

with open("file_b", "r") fb:     all_lines_except_header = numpy.loadtxt(fb, skiprows=1) 

this parse csv file, however. if you're interested in lines , not in individual fields, recommend first method.


Comments

Popular posts from this blog

c++ - OpenCV Error: Assertion failed <scn == 3 ::scn == 4> in unknown function, -

php - render data via PDO::FETCH_FUNC vs loop -

The canvas has been tainted by cross-origin data in chrome only -