0

I have a number of .csv files which I am opening in Python3. Some open fine and the script runs fine, others I get the below error

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

If I tell Python to ignore errors as below

dataset = open('data.csv', 'r', errors='inore')

The script then runs but it adds quotation marks around each column header in the .csv e.g.

"No.","Time","Source","Destination"

How can I open the .csv without the quotation marks, as per the others that already do this e.g. below

 No.,Time,Source,Destination

I have tried this running on Linux Mint 18.3 with Python 3.6.4 and Mac OSx with Python 3.6.3 and get same results on both. I do not have a windows PC to try.

2
  • Why would open change file contents? Commented Jun 19, 2018 at 9:21
  • I'm not suer if it is or whether it is the way the file was previously saved. I thought open() handled utf-8 fine Commented Jun 19, 2018 at 9:24

1 Answer 1

1

try to strip the string mate :)

a ="\"a\""
print(a.strip("\""))

or replace the "

a.replace("\"", "")
Sign up to request clarification or add additional context in comments.

2 Comments

thanks for the suggestion. What I find strange is that I checked the encoding of two files (one which works and the other that does the above) and they both say us-ascii. I can't figure out why the script treats two files differently.
@Bat, can you share the two files in your question?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.