Home > Software engineering >  Import arabic CSV file using python
Import arabic CSV file using python

Time:05-05

I have a .CSV file containing Arabic data and I need to view this file in jupyter using python and pandas. But I have a problem with the encoding What should I do ? any ideas please ? This is my code

And this is the error

CodePudding user response:

you might need to save the original CSV file as mentioned in this link CSV file with Arabic characters is displayed as symbols in Excel

CodePudding user response:

I have never encountered a problem like this before, but it seems that it is a problem in the decoding. Check this question, it might help.

What you can always do is to check the encoding of your file; maybe is something else and not 'utf-8'. The following code will help you do this:

from bs4 import UnicodeDammit

filename="absolute_path_of_your_file"

with open(filename, "rb") as file:
    content = file.read()

suggestion = UnicodeDammit(content)
suggestion.original_encoding

The output will be the encoding of your file. I hope it helps and that I've correctly understood your problem.

  • Related