0

I have searched everywhere for a solution for this particular error and tried them all and none worked I have searched in this forum and worked out every answer and it did not work at all.

This is my code:

X_train, Y_train = read_csv('Data/train_emoji_ar.csv')

this is the error I keep getting

Error                                     Traceback (most recent call last)
<ipython-input-2-3f5fe77b4b07> in <module>
----> 1 X_train, Y_train = read_csv('Data/train_emoji_ar.csv')

~\emo_utils.py in read_csv(filename)
     38         csvReader = csv.reader(csvDataFile)
     39 
---> 40         for row in csvReader:
     41             phrase.append(row[0])
     42             emoji.append(row[1])

Error: line contains NULL byte

and when I open my CSV file that is saved in jupyter note book I see this error:

enter image description here

However, when it is in English it works fine and opens fine unlike when it is in arabic.

The part of my python code in my emo_utils.py which reads the csv:

def read_csv(filename):
    phrase = []
    emoji = []

    with open (filename) as csvDataFile:
        csvReader = csv.reader(csvDataFile)

        for row in csvReader:
            phrase.append(row[0])
            emoji.append(row[1])

    X = np.asanyarray(phrase)
    Y = np.asanyarray(emoji, dtype=int)

    return X, Y

so please help me why I keep getting this issue:

I tried using UTF encoding newline and many

None worked

MattDMo
  • 100,794
  • 21
  • 241
  • 231
Abdulmajeed
  • 1,502
  • 2
  • 10
  • 13
  • 1
    Does this answer your question? [Python CSV error: line contains NULL byte](https://stackoverflow.com/questions/4166070/python-csv-error-line-contains-null-byte) – Michael Ruth Jul 03 '21 at 21:33
  • The problem is that jupyter notebook is not reading the CSV file I am uploading – Abdulmajeed Jul 04 '21 at 07:43
  • Is the error in this post not `Error: line contains NULL byte`? And is the error in [Python CSV error: line contains NULL byte](https://stackoverflow.com/questions/4166070/python-csv-error-line-contains-null-byte) not `error: line contains NULL byte`? I understand that this isn't a bespoke solution, but it appears to be the same root cause. Have you tried opening the file in binary mode, and if so: what happened? – Michael Ruth Jul 05 '21 at 07:24

0 Answers0