Created
March 7, 2014 12:50
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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