vaia-dataset-ic / categorical2int.py
tsinik's picture
Initial upload
6ce882c verified
import csv
# This script transforms categorical labels to integer
# Define the mapping
mapping = {
'information': '0',
'cuisine': '1',
'directions': '2',
'reservations': '3',
'open_hours': '4',
'rating': '5'
}
# Open the input file in read mode and output file in write mode
with open('train-intent-dataset-categorical.csv', 'r') as infile, open('output.csv', 'w', newline='') as outfile:
# Create a CSV reader and writer
reader = csv.reader(infile)
writer = csv.writer(outfile)
# Iterate over each row in the input CSV
for row in reader:
# If the first column value is in the mapping, replace it
if row[0] in mapping:
row[0] = mapping[row[0]]
# Write the row to the output CSV
writer.writerow(row)