INNER CODE UNIT · Python
process_and_split_csv
DrewThomasson/VoxNovel · 1CPU_Book_processing.py:72
def process_and_split_csv(file_path, split_string):
def split_text(text, split_string, original_row):
# Split the text at the specified string and find the index of the split
split_index = text.find(split_string)
parts = text.split(split_string)
new_rows = []
start_location = original_row['Start Location']
for index, part in enumerate(parts):
new_row = original_row.copy()
if index == 0:
new_row['Text'] = part
new_row['End Location'] = start_location + split_index
else:
new_row['Text'] = split_string + part
new_row['Start Location'] = start_location + split_index
new_row['End Location'] = start_location + split_index + len(split_string) + len(part)
split_index += len(split_string) + len(part) # Update for the next part