python2.7读汉字的时候出现乱码,如何解决

我使用的是window系统,安装Anaconda,所以用的是

1.数据形式

2.读进来乱码

3.解决办法

3.1方法1

import pandas as pd

#pd.read_csv('c:/users/thinkpad/desktop/1.csv')

pd.read_csv('c:/users/thinkpad/desktop/1.csv',encoding='gb2312')

3.2方法2

import pandas as pd
import codecs 
  def ReadFile(filePath,encoding): 
    with codecs.open(filePath,"r",encoding) as f: 
        return f.read() 
def WriteFile(filePath,u,encoding): 
    with codecs.open(filePath,"w",encoding) as f: 
        f.write(u) 
def GBK_2_UTF8(src,dst): 
    content = ReadFile(src,encoding='gbk') 
    WriteFile(dst,content,encoding='utf_8') 
src = 'C:/Users/Thinkpad/Desktop/1.csv' 
dst = 'C:/Users/Thinkpad/Desktop/1_utf8.csv' 
GBK_2_UTF8(src,dst) 
path = 'C:/Users/Thinkpad/Desktop/1_utf8.csv' 
data = pd.read_csv(path,)  
data

原文地址:https://www.cnblogs.com/llfisher/p/6343687.html