Skip to content

Instantly share code, notes, and snippets.

@coppeliaMLA
Created March 7, 2014 12:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save coppeliaMLA/9410889 to your computer and use it in GitHub Desktop.
Save coppeliaMLA/9410889 to your computer and use it in GitHub Desktop.
Another useful bit of code for preparing flat files for Hive. Takes in csvs with double quote text delimiters and outputs pipe delimited files.
import os, csv
progDir = '/pathToFolderContainingCSVs/'
for filename in os.listdir(progDir):
if filename != '.DS_Store':
with open(progDir+filename, 'rb') as csvfile:
progReader = csv.reader(csvfile, delimiter=',', quotechar='"')
with open(progDir+filename[:-4] + "T.txt", 'wb') as f:
writer = csv.writer(f, delimiter='\t')
for row in progReader:
writer.writerow(row)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment