UnicodeDecodeError utf-8 codec can t decode byte 0x8b in position 1 invalid start byte

0 votes

hi, guys, I need to deal with a zipped CSV file ......but getting this error again and again

import gzip
import csv
import pandas as pd
with gzip.open(path) as f:
    features_train = pd.read_csv(f)
features_train.head() 
Jul 15, 2020 in Python by Himanshu
• 120 points

edited Jul 15, 2020 by MD 4,555 views

2 answers to this question.

0 votes

Hi@Himanshu,

This type of error will occur if there is any problem to decode any value. To avoid this you can follow the below-given code. 

$ features_train = pd.read_csv('csv_file', encoding='ISO-8859–1')
answered Jul 15, 2020 by MD
• 95,220 points
0 votes

Hey,  @Himanshu.

It's still most likely gzipped data. gzip's the magic number is 0x1f 0x8b, which is consistent with the UnicodeDecodeError you get.


answered Jul 27, 2020 by Gitika
• 65,910 points

Related Questions In Python

+2 votes
2 answers

UnicodeDecodeError: "utf-8" codec can't decode byte in position : invalid start byte

You have to use the encoding as latin1 ...READ MORE

answered Jul 23, 2019 in Python by Kunal
112,082 views
0 votes
1 answer

UnicodeDecodeError: 'utf-8' codec can't decode byte 0x89 in position 0: invalid start byte

Hi, @hala, Regarding your query, you can go ...READ MORE

answered Jun 29, 2020 in Python by Niroj
• 82,760 points
5,806 views
+3 votes
4 answers
0 votes
0 answers

utf-8' codec can't decode byte 0xa0 in position 10: invalid start byte

my code import wordcloud import numpy as np from matplotlib ...READ MORE

Mar 29, 2020 in Python by anonymous
• 120 points
2,443 views
0 votes
1 answer

Python: Issue with 'unexpected end of pattern'

I should start by stating that using ...READ MORE

answered Sep 12, 2018 in Python by Priyaj
• 58,120 points
830 views
0 votes
1 answer

Python: Issue with 'unexpected end of pattern'

I should start by stating that using ...READ MORE

answered Sep 24, 2018 in Python by Priyaj
• 58,120 points
714 views
0 votes
1 answer

Reading a CSV file using Python 3

A simple "if" statement should suffice. you ...READ MORE

answered Mar 26, 2019 in Python by SDeb
• 13,290 points
1,074 views
0 votes
1 answer

Splitting a column with multiple values in python

Try using the following: df['id'] = df.index+1 df.set_index('id').col_name.str.split(',', expand ...READ MORE

answered Jul 9, 2019 in Python by SDeb
• 13,290 points
1,597 views
0 votes
2 answers
0 votes
1 answer

'utf-8' codec can't decode byte 0x82 in position 16: invalid start byte

Hi@zena, The error is because there is some non-ASCII ...READ MORE

answered Jun 29, 2020 in Python by MD
• 95,220 points
2,606 views