-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathseparator.py
More file actions
executable file
·48 lines (36 loc) · 1.5 KB
/
separator.py
File metadata and controls
executable file
·48 lines (36 loc) · 1.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import csv
# Open the input CSV file
with open('school.csv', 'r', encoding='utf-8', errors='replace') as input_file:
# Create a CSV reader object
reader = csv.reader(input_file)
# Skip the header row if present
header = next(reader)
# Initialize variables
row_count = 0
page_count = 1
output_file = None
output_writer = None
# Iterate over each row in the input file
for row in reader:
# Remove double quotation marks from each value in the row
row_without_quotes = [value.replace('"', '') for value in row]
# Check if a new page needs to be started
if row_count % 400 == 0:
# Close the previous output file if open
if output_file is not None:
output_file.close()
# Create a new output CSV file
output_file = open(f'schoool_{page_count}.csv', 'w', newline='')
output_writer = csv.writer(output_file)
# Write the header row to the new output file
output_writer.writerow(header)
# Increment the page count
page_count += 1
# Write the modified row (without double quotation marks) to the current output file
output_writer.writerow(row_without_quotes)
# Increment the row count
row_count += 1
# Close the last output file
if output_file is not None:
output_file.close()
print('Separation complete.')