How to use 'merge multiple csv files into one python' in Python

Every line of 'merge multiple csv files into one python' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your Python code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
11def merge(columns, files):
12 #first read all csv files to an 3-dim array raw-csv[file][line][column]
13 raw_csv = []
14 for f in files:
15 csv_arr=[]
16 for line in file(f).readlines():
17 csv_arr.append([elem.strip() for elem in line.split(",")])
18 raw_csv.append(csv_arr)
19
20 #now create new file
21 result = []
22 for bench_index in xrange(len(raw_csv[0])):
23 for f in xrange(len(files)):
24 result.append(", ".join(raw_csv[f][bench_index]))
25 result.extend(["",""])
26
27 return "\n".join(result)

Related snippets