Writing charcters in the csv files instead of writing the sentence

40 Views Asked by At

I want to save my data in the CSV format, I have some sentences and I want to save every sentence in a different row, but the output is like this: enter image description here

This is my code:

with jsonlines.open('/content/data.jsonl') as reader:
    with open('/content/sample_data/sents.csv', 'w') as csv_file:
      writer = csv.writer(csv_file, delimiter=',')
      for obj in reader:
          if obj['label']=='ENOUGH':
              writer.writerow(obj['sent'])

and this is a piece of my data:

1 Cameroon lists three definitely endangered languages, 13 severely endangered, and 16 critically endangered from among its at least 250 languages.
2 Ryan Mathews of the 2003 Kansas State Wildcats football team posted a higher rushing average than his teammate Ell Roberson.
3 Alan Lowry only played games with his close relatives in his entire life.

I want to save them in differenet rows and a single column. what should I do?

1

There are 1 best solutions below

0
On

I use pandas package for my purpose. These are important links that I used: pandas.DataFrame.to_csv and pandas.DataFrame.from_dict. I hope you find them useful too.