ab / breakdown1.py
theapps's picture
Upload 36 files
ca165c7 verified
raw
history blame contribute delete
925 Bytes
import csv
def process_csv(input_file, output_file):
with open(input_file, 'r') as csvfile:
reader = csv.reader(csvfile)
next(reader) # Skip header row
output_data = []
for row in reader:
word, score = row[0], int(row[1])
if score == 1:
# Break down the word into letters and append each letter with ,1
for letter in word:
output_data.append([letter, '1'])
else:
output_data.append([word, str(score)])
with open(output_file, 'w', newline='') as csvfile:
writer = csv.writer(csvfile)
writer.writerow(['Letter', 'Score'])
writer.writerows(output_data)
if __name__ == "__main__":
input_csv = "word_scores.csv"
output_csv = "word_scores2.csv"
process_csv(input_csv, output_csv)
print(f"Conversion complete. Output saved to {output_csv}")