I'm new to python but I'm having trouble reading a text file which contains data separated by "|" as the delimiter. How would I separate the file into columns in a CSV format.
import csv
my_file_name = "NVG.txt"
cleaned_file = "cleanNVG.csv"
with open(my_file_name, 'r') as infile, open(cleaned_file, 'w') as outfile:
data = infile.read()
data = data.replace("|","")
outfile.write(data)
This code gets rid of the | to a blank but all the data is just in one column now. How can I format this correctly? I appreciate your help in advance.
csvthat that is your separator? i.e.csv.reader(infile, delimiter='|')