Stuck openning the file in the first project NUL

Hi¡

I will appreciate your help

I tried to open the file Applestore.csv with this code

opened_file = open(‘AppleStore.csv’,encoding=‘utf-8’)
from csv import reader
read_file = reader(opened_file)
apps_data = list(read_file)

def explore_data(dataset, start, end, rows_and_columns=False):
dataset_slice = dataset[start:end]
for row in dataset_slice:
print(row)
print(’\n’) # adds a new (empty) line after each row

if rows_and_columns:
    print('Number of rows:', len(dataset))
    print('Number of columns:', len(dataset[0]))

And GET THIS ERROR

UnicodeDecodeError: ‘utf-8’ codec can’t decode byte 0xd1 in position 8: invalid continuation byte

THen I tried with latin-1

opened_file = open(‘AppleStore.csv’,encoding=‘latin-1’)
from csv import reader
read_file = reader(opened_file)
apps_data = list(read_file)

def explore_data(dataset, start, end, rows_and_columns=False):
dataset_slice = dataset[start:end]
for row in dataset_slice:
print(row)
print(’\n’) # adds a new (empty) line after each row

if rows_and_columns:
    print('Number of rows:', len(dataset))
    print('Number of columns:', len(dataset[0]))

And get this ERROR

Error Traceback (most recent call last)
in
2 from csv import reader
3 read_file = reader(opened_file)
----> 4 apps_data = list(read_file)
5
6

Error: line contains NUL

I do not know what to do, please I appreciate your help to solve the problem

Thank you

I tried this it is working fine

Even without encoding it is working.

Can you provide full error message or screen shot?

here it is fhe full error
+

Error Traceback (most recent call last)
in
2 from csv import reader
3 read_file = reader(opened_file)
----> 4 apps_data = list(read_file)
5
6

Error: line contains NUL

THank you very much , I cannot open it with UTF-8

And if I use again UTF-8 thi is the error, I am totally lost ;-(

UnicodeDecodeError Traceback (most recent call last)
in
2 from csv import reader
3 read_file = reader(opened_file)
----> 4 apps_data = list(read_file)
5
6

/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/codecs.py in decode(self, input, final)
320 # decode input (taking the buffer into account)
321 data = self.buffer + input
–> 322 (result, consumed) = self._buffer_decode(data, self.errors, final)
323 # keep undecoded input until the next call
324 self.buffer = data[consumed:]

UnicodeDecodeError: ‘utf-8’ codec can’t decode byte 0xd1 in position 8: invalid continuation byte

Hi @JPQ

While I was doing this project “UTF-8” did work for me.

I’m not sure why you are getting this error. But maybe you can try a few things which might work.

  • I know that utf-8 isn’t case sensitive. But maybe you can try the Uppercase and see if it makes any difference.
  • Or Try opened_file = open(r‘AppleStore.csv’,encoding=‘UTF-8’)
  • Also please let us know if this problem occurs only for Applestore data set or for googleplaystore data set as well.

In case if you want to find out the encoding you can try this

import chardet
with open(filename, 'rb') as rawdata:
    result = chardet.detect(rawdata.read(100000))
print(result)

And apply whichever encoding it suggests. 

Thank you very much Jitknis, I tried with upper case and it continue witj the error, but running the detect, i realize there was some error in the CSV file, I downloaded again from dataquest link and know I can open it¡¡ thank you¡¡