| 1 |
"""
|
| 2 |
|
| 3 |
EndoCsvFieldDataExtractor
|
| 4 |
|
| 5 |
Created by:
|
| 6 |
Emanuel Borges
|
| 7 |
09.09.2021
|
| 8 |
|
| 9 |
Very simple program that will read a CSV and export a column to a text file for me.
|
| 10 |
|
| 11 |
"""
|
| 12 |
|
| 13 |
import csv, os
|
| 14 |
|
| 15 |
if __name__ == '__main__':
|
| 16 |
csvFileName = r"C:\Users\eborges\Documents\Cases\Endo\Temp\Navigator EAT Table Dumps_09.08.2021\AFFILIATION.csv"
|
| 17 |
fieldToExport = "Comments"
|
| 18 |
outputPath = r"C:\Users\eborges\Documents\Cases\Endo\Temp\2021.08.18 IQVIA - Navigator data dictionary\_Suppl"
|
| 19 |
|
| 20 |
outputFileName = os.path.join(outputPath,os.path.splitext(os.path.split(csvFileName)[-1])[0]+"-"+ fieldToExport +".txt")
|
| 21 |
|
| 22 |
|
| 23 |
tempList = []
|
| 24 |
with open(csvFileName,mode='r') as csv_file:
|
| 25 |
csv_reader = csv.DictReader(csv_file)
|
| 26 |
for row in csv_reader:
|
| 27 |
tempList.append(row[fieldToExport])
|
| 28 |
|
| 29 |
outputFile = open(outputFileName,'w')
|
| 30 |
for i in tempList:
|
| 31 |
if i:
|
| 32 |
nl = outputFile.write("%s\n"%i)
|
| 33 |
outputFile.close() |