Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Combine data from several csv files
import glob
import pandas as pd
path ='/' # use your path
allFiles = glob.glob("*.csv")
frame = pd.DataFrame()
list_ = []
for file_ in allFiles:
df = pd.read_csv(file_,index_col=None, header=None)
frame = pd.concat(list_)
frame.columns = ['SN', 'State', 'LGA', 'Ward', 'Polling Units', 'dd', 'dd2', 'dd3', 'dd4', 'dd5']
cleaned = frame.drop(axis=1, labels=['dd', 'dd2', 'dd3', 'dd4', 'dd5'])
cleaned.to_csv('combined_csv.csv', index=False)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.