Python csv模塊讀csv文件,編碼問題處理
import csv
file_rute:文件路徑
with open(file_rute,"r+") as csvfile:
reader=csv.reader(csvfile)
for i,rows in enumerate(reader):
#i=行數
#rows=行的數據,爲list
#處理csv數據邏輯
這樣讀取csv文件,讀取的數據格式是:IBM855
{‘confidence’: 0.31998738481734096, ‘language’: ‘Russian’, ‘encoding’: ‘IBM855’}
就會出現中文編碼問題,只需要轉換爲
_app_name=app_name.decode(‘GB2312’).encode(‘utf-8’)
這樣就轉換成utf8格式