Extract Unicode data from CSV file
Question: I have a CSV file like this encoding UTF-8

    
    
    # id    english_word    part_of_speech  malayalam_definition
    174569  .net    n   പുത്തന്‍ കമ്പ്യൂട്ടര്‍ സാങ്കേതികത ഭാഷ
    116102  A bad patch n   കുഴപ്പം പിടിച്ച സമയം
    115869  A bed of nails  n   പ്രയാസപ്പെടുന്ന അവസ്ഥ
    200587  A bed of nails  idm ശരശയ്യ
    115768  A bed of roses  n   സുഖകരമായ അവസ്ഥ
    115767  A bed of roses  n   പൂമെത്ത
    113832  A bed of thorn  n   അസുഖകരമായ അവസ്ഥ
    113665  A bed roses n   പൂമെത്ത
    

I have to extract all Unicode data from the file having `n` tag

    
    
    import csv
    with open('some.csv', newline='\t', encoding='utf-8') as f:
        reader = csv.reader(f)
        for row in reader:
            print(row)
    

This is the code I have but it is not working The code is not producing
output, it does not . Any suggestions ?

Python 2.7


Answer: You have to read the csv file before you iterate in it with `for row in f`.

First, import the csv package:

    
    
    import csv
    

After, read the csv file:

    
    
    with open('mycsv.csv','r') as f:
      with open('n.csv','w') as new_file:
        file_read = csv.reader(f,delimiter=';')
        for row in file_read:
          if not extract_n(row):
            new_file.write(row)
    

The delimiter field can be a semicolon, comma, o whatever you have.

