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 24,963 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,460 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,770 points

Related Questions In Python

+3 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
247,714 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,840 points
17,578 views
+5 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
5,254 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,020 points
2,631 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,300 points
1,980 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,300 points
3,277 views
0 votes
1 answer

Error:UnicodeDecodeError when reading CSV file in Pandas with Python

Hello @kartik, Try this: import pandas as pd df = ...READ MORE

answered Jun 15, 2020 in Python by Niroj
• 82,840 points
7,830 views
0 votes
2 answers

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

Thanks, This answer was helpful. READ MORE

answered Jul 11, 2020 in Python by Prashant Chhatrashali
16,817 views
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,460 points
15,922 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP