Skip to content

Commit 32ea397

Browse files
committed
Merge csv script using pandas library
Merges CSV for a specific directory, using glob to get all of the files and then pandas to create dataframes and do merging.
1 parent 3ab6f7e commit 32ea397

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

merge.py

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import glob
2+
import csv
3+
import pdb
4+
import os
5+
import pandas as pd
6+
7+
def main():
8+
directory = []
9+
for dirs in os.walk("."):
10+
directory.append(dirs)
11+
folders = directory[0][1]
12+
for ff in folders:
13+
if ff != ".git":
14+
allFiles = glob.glob(ff + "/*.csv")
15+
frame = pd.DataFrame()
16+
dfs = []
17+
for files in allFiles:
18+
df = pd.read_csv(files,index_col=None, header=0)
19+
dfs.append(df)
20+
frame = pd.concat(dfs)
21+
frame.to_csv(ff+"/results.csv")
22+
main()

0 commit comments

Comments
 (0)