I chose csv's specific column and converted it to txt.
The selected column name is 'id' (header) and I don't know how to remove that 'id' from txt.
This is my code..
import csv
with open('garosu_example.csv') as file:
reader = csv.reader(file)
input_file = "garosu_example.csv"
output_file = "garosu_example.txt"
id = ['id']
selected_column_index = []
with open(input_file, 'r', newline='') as csv_in_file:
with open(output_file, 'w', newline='/n') as csv_out_file:
freader = csv.reader(csv_in_file)
fwriter = csv.writer(csv_out_file)
header = next(freader)
for index_value in range(len(header)):
if header[index_value] in id:
selected_column_index.append(index_value)
print(id)
fwriter.writerow(id)
for row_list in freader:
row_list_output = []
for index_value in selected_column_index:
row_list_output.append(row_list[index_value])
print(row_list_output)
f.writer.writerow(row_list_output)
How can I remove 'id'(header) from txt file?
If I remove header in csv, output txt file is emptyT_T
