I have multiple csv files that all have more or less the same headers. some might have all the headers some might not have them all. I want to use a common csv file that will have only the headers and merge them all.
sample header:
a, b, c, d, e, f,
file 1:
a, b, d,
1, 2, 3,
file 2:
a, b, c, e,
4, 5, 6, 7,
Merged result:
a, b, c, d, e, f,
1, 2, , 3,
4, 5, 6, , 7, ,
So far I was pointed to use csv.DictReader, csv.DictWriter. But I am having trouble with merging based on a common header and also keeping the header order. Is there anyway I could still use them and not sort them?
I tried pandas merge function but it needs an order to sort based on, which my data do not contain.
Any help is appreciated. Thank you
strip(',')andsplit(', ')to parse input and then use an iterator towrite()to the files?