Sib007 / intro_machine_learning_using_python

0 stars 0 forks source link

Writing a tab-separated file #1

Open montesmariana opened 1 year ago

montesmariana commented 1 year ago

This is the code we saw earlier:

split_st_1 = ["Sentence1", "Sentence2", "Sentence3"] # list of lines of one text
split_tt_1 = ["Oración1", "Oración2", "Oración3"] # list of lines of the other text
with open("translation_memory.csv", "w", encoding = "utf-8") as f: # open file to overwrite
    f.write("EN\tES\n") # write heading
    for x, y in zip(split_st_1, split_tt_1): # go through each pair of lines
        f.write(f"{x}\t{y}\n") # write the line

When you open it later with pandas, remember to specify that the separator is '\t'!

Sib007 commented 1 year ago

Thank you for this code!