How can I read a csv persian file in python?

1.6k Views Asked by At

I am trying to read a non-English .csv file in python but I am facing an encoding error. Can you please help me to solve this problem?

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

Code used:

import pandas as pd 

with open('1.csv', encoding="utf-8") as f: 
    train = f.read().splitlines() 
    print(train)
1

There are 1 best solutions below

4
Ehsan On

Actually i think your file encoding is inappropriate. I used below code for many Persian csv files and it works!

import csv
with open('file.csv') as csv_file:
    csv_reader = csv.reader(csv_file, delimiter=',')
    line_count = 0
    for row in csv_reader:
        print(row)