爬取中文网页后正则匹配出中文,得打UTF-8的编码字符
将其输出为.csv文件
在.CSV中显示为乱码
用记事本打开.csv又可以正常显示为中文
有没有大神指点是怎么一回事?怎样才能在Excel里直接看到中文?
PHP中文网2017-04-18 10:28:54
The simple way is to use pandas
的to_excel
方法转化成.xlsx
文件,因为.xlsx
The default encoding supports Excel by default. The difference is of course that it cannot be opened with Notepad.
import pandas as pd
a = pd.read_csv('./test.csv')
a.to_excel('./test_output.xlsx', index=False)
a.to_excel('./test_output.csv', index=False)
I don’t have windows here to test, you can try to write the encoding as gb2312
或者gbk
.
For table file I/O, pandas is actually more convenient.
PHP中文网2017-04-18 10:28:54
Create a new excel file, then click Data from text to import the csv file