You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
15 lines
622 B
15 lines
622 B
import csv |
|
|
|
# Preprocess the CSV file to ensure consistent field counts |
|
input_file = 'speeches.csv' |
|
output_file = 'cleaned_speeches.csv' |
|
|
|
with open(input_file, 'r', encoding='utf-8') as infile, open(output_file, 'w', encoding='utf-8', newline='') as outfile: |
|
reader = csv.reader(infile, delimiter=';', quotechar='"') |
|
writer = csv.writer(outfile, delimiter=';', quotechar='"', quoting=csv.QUOTE_MINIMAL) |
|
|
|
for row in reader: |
|
if len(row) == 22: # Ensure the row has the correct number of fields |
|
writer.writerow(row) |
|
|
|
print("CSV file has been cleaned and saved as 'cleaned_speeches.csv'")
|
|
|