how to merge multiple CSV files into one file and create super schema in final CSV file using python

422 views Asked by At

how to merge multiple CSV files into one CSV file in the python 2.4 version(python 2.x). I want to merge almost 30 CSV files into a single CSV file. The final CSV file contains super schema columns(all columns from each file). non-available column values consider for empty value or blank space value in the final CSV file.

first file:

file111.csv:
"E_TYPE","TIMESTAMP","EXEC_TIME","DBT_TIME","CALLOUT_TIME","CLIENT_IP"
"BBCout","20191011000022.423","95","0","2019-01-11T00:00:05.300Z","200.50.000.333" 
"BBCout","20200403122024.123","96","1","2020-04-03T00:00:05.300Z","300.50.000.333"
"BBCout","20210102083426.543","92","0","2021-01-02T00:00:05.300Z","400.50.000.333"

second file:

file222.csv:
"E_TYPE","TIMESTAMP","TYPE","METHOD","TIME","RT_SIZE","URL","UID_DERIVED","CLIENT_IP"
"AACallout","20210215000030.815","REST","POST","61","71","""https://st.aaa.xxx.net/n1/yyy/zzz""","0055QAQ","200.50.000.333"
"AACallout","20201210000012.800","REST","GET","67","75","""https://st.aaa.xxx.net/n1/yyy/zzz""","0055BBBQ","300.00.000.111"

final merged CSV should contain all columns and non-available columns should be empty values or blank space.

final CSV file.

result.csv

"E_TYPE","TIMESTAMP","CLIENT_IP","EXEC_TIME","DBT_TIME","CALLOUT_TIME","TYPE","METHOD","TIME","RT_SIZE","URL","UID_DERIVED"
"BBCout","20191011000022.423","200.50.000.333","95","0","2019-01-11T00:00:05.300Z",,,,,,
"BBCout","20200403122024.123","300.50.000.333","96","1","2020-04-03T00:00:05.300Z",,,,,,
"BBCout","20210102083426.543","400.50.000.333","92","0","2021-01-02T00:00:05.300Z",,,,,,
"AACallout","20210215000030.815","200.50.000.333",,,,"REST","POST","61","71","""https://st.aaa.xxx.net/n1/yyy/zzz""","0055QAQ"
"AACallout","20201210000012.800","300.00.000.111",,,,"REST","GET","67","75","""https://st.aaa.xxx.net/n1/yyy/zzz""","0055BBBQ"
1

There are 1 answers

0
shark On

You can use pandas.DataFrame.append to achieve just that!

Combining two csv files using pandas

pandas.DataFrame.append