[python]python 读写 Excel文件
python 读写 Excel文件一、用xlrd和xlwt读写excel
首先下载安装xlrd和xlwt这两个库。附件中有这两个库的下载,可以直接下载
代码在python2.7+win10下通过
"""
This is a script to parse child labor and child marriage data.
The excel file used in this script can be found here:
http://www.unicef.org/sowc2014/numbers/
"""
import xlrd
book = xlrd.open_workbook("SOWC 2014 Stat Tables_Table 9.xlsx")
sheet = book.sheet_by_name("Table 9 ")
data = {}
for i in xrange(14, sheet.nrows):
# Start at 14th row, because that is where the countries begin
row = sheet.row_values(i)
country = row
data = {
'child_labor': {
'total': , row],
'male': , row],
'female': , row],
},
'child_marriage': {
'married_by_15': , row],
'married_by_18': , row],
}
}
if country == "Zimbabwe":
break
import pprint
pprint.pprint(data)
代码运行结果如下:
附件内容包括本例中的代码及数据,还有需要模块的文件。
链接:https://pan.baidu.com/s/1zOia7QXfTToFxGZbex8FaQ
附件下载:
页:
[1]