I have three CSV's that I am attempting to merge together. The three CSV's have a range of different columns though all 3 have a set of columns that are consistent between them.
I have the column headers for these columns stored in a Python List as strings. These columns are the only ones I want to merge.
As a side note, I have attempted to implement an answer in this thread using a library called brewery though am recieving an error message
'CSVDataSource' object has no attribute 'field_names'
I feel that this could be easily done using the CSV module though am unsure how to go about searching each CSV for the right columns and then only merging those columns. Another issue I am unsure on how to approach is ensuring the correct positioning of each column throughout the merged CSV. IE if columnA is the 5th across in the 1st CSV and then is the 4th across in the 2nd CSV how will I ensure they are in the same position in the merged CSV?
I am using Python 2.7 and unfortunately don't have access to Pandas.
Code example:
Columns_to_Merge = ['ColumnA','ColumnB','ColumnC']
# CSV1
ColumnA,ColumnB,ColumnF,ColumnC
2,3,4,9
8,2,5,7
1,2,3,4
# CSV2
ColumnD,ColumnA,ColumnC,ColumnB,ColumnH
2,3,4,9,12
8,2,5,7,2
1,2,3,4,5
# CSV3
ColumnH,ColumnJ,ColumnA,ColumnB,ColumnC
2,3,4,99,12
8,5,5,7,2
1,55,3,70,5