如何在python中读取csv波斯文件?

时间:2018-05-21 15:46:01

标签: python python-3.x pandas csv persian

我正在尝试在python中读取非英语.csv文件,但我面临编码错误。能帮我解决这个问题吗?

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

使用的代码:

import pandas as pd 

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

1 个答案:

答案 0 :(得分:1)

实际上,我认为您的文件编码不合适。我在下面的代码中使用了许多波斯的csv文件,并且可以正常工作!

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)