The csv-splitter script is the following:
csv-splitter.py:
import csv
def write_new_csv(csv_file_write, column_headers, split_number):
writer = csv.DictWriter(csv_file_write, fieldnames=column_headers)
writer.writeheader()
return writer
def loop_through_csv(csv, split_threshold, column_headers, output_name):
row_counter = 0
split_number = 0
write_csv = None
for row in csv:
if (row_counter == 0) or (row_counter == split_threshold):
# close file if it already exists before writing to a new csv file
if write_csv:
write_csv.close()
split_number += 1
write_csv = open(f'{output_name}.{split_number}.csv', 'w')
writer = write_new_csv(write_csv, column_headers, split_number)
writer.writerow(row)
row_counter = 0
else:
writer.writerow(row)
row_counter += 1
def main():
# grab inputs from user
csv_file_path = input('Enter csv file path: ')
split_threshold = int(input('Enter how many rows per CSV file you would like: '))
output_name = input('Name prefix of the output files: ')
with open(csv_file_path) as csv_file:
csv_reader = csv.DictReader(csv_file)
column_headers = csv_reader.fieldnames
loop_through_csv(csv_reader, split_threshold, column_headers, output_name)
if __name__ == "__main__":
main()
And to execute it:
$> python3 csv-splitter.py
Enter csv file path: your-file.csv
Enter how many rows per CSV file you would like: 200
Name prefix of the output files: your-label
For the DSP error, unfortunately, I don’t have an nRF52833 SoC with me at the moment.
I’ll try to check internally if someone has more info.
Regards,
Louis