-
Notifications
You must be signed in to change notification settings - Fork 0
/
MergeToCSV.py
33 lines (28 loc) · 1.08 KB
/
MergeToCSV.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# Name: Mergecsv
# Purpose: To pull in csv files with the same structure into 1 file
#
# Author: Michael O'Brien
# Created: Dec 2015
#===============================================================================
import pandas as pd
import os
def main(CombinedFileName ="Combined.csv"):
#Create an list to store the list of objects/csv files
Combinedlist =[]
Colnames = ['Method', 'CreatedDate', 'Coordinates','userLocation','id', 'retweetCount','text']
print(Colnames)
# Get all the csv files in the current directory
for fileToProcess in os.listdir(os.curdir):
if fileToProcess.endswith(".csv"):
print(fileToProcess)
df=pd.read_csv(fileToProcess,sep='|')
#df = pd.read_csv(file_,index_col=None, header=0)
Combinedlist.append(df)
#Concat the files vertically
concatDf =pd.concat(Combinedlist)
#concatDf.columns=Colnames
concatDf.to_csv(CombinedFileName)
print(concatDf.head(10))
# frame = pd.concat(Combinedlist)
if __name__ == '__main__':
main()