Excel 文件
mac 一定要注意添加执行权限第二行代码导入 xlrd 模块的 open_workbook 函数来读取和分析 Excel 文件, 第六行代码使用 open_workbook 函数来打开一个 Excel 输入文件, 并赋给一个名为 workbook 的对象 workbook 对象中包含了工作簿中所有可用信息, 所以可以使用这个对象从工作簿中得到单独的工作表第七行代码打印出工作簿中工作表的数量第八行是一个 for 循环语句, 在工作簿中的所有工作表之间迭代 workbook 对象的 sheets 方法可以识别出工作簿中工作表的数量第九行打印每个工作表中列于行的数量 print 语句使用 worksheet 对象 name 属性来确定每个工作表的名称同样, 它使用 nrows 和 ncols 属性来分别确定每个工作表中行和列的数量
sys.argv 官方文档
The list of command line arguments passed to a Python script. argv[0] is the script name (it is operating system dependent whether this is a full pathname or not). If the command was executed using the -c command line option to the interpreter, argv[0] is set to the string '-c'. If no script name was passed to the Python interpreter, argv[0] is the empty string.
传递给 Python 脚本的命令行参数列表 argv [0]是脚本名称 (与操作系统有关, 无论这是否是完整的路径名) 如果使用解释器的 - c 命令行选项执行该命令, argv [0] 被设置为字符串'-c' 如果没有脚本名称被传递给 Python 解释器, argv [0]是空字符串
处理单个工作表
第二行代码导入 xlrd 模块的 open_workbook 函数, 第三行代码导入 xlwt 模块的 Workbook 对象第八行实例化一个 xlwt workbook 对象, 以使我们可以将结果写入用于输出的 Execl 文件后面使用 xlwt 的 add_sheet 函数为输出工作簿中添加一个工作表后面使用 open_workbook 函数打开用于输出的工作簿, 并将结果赋值给一个 workbook 对象下一行使用 workbook 对象的 sheet_by_name 函数引用名称为 x x x_2013 的工作表, 后创建行与列的索引值上的 for 循环语句, 使用 range 函数和 worksheet 对象的 norws 属性和 ncols 属性, 在工作表的每行和每列之间迭代最后保存关闭输出工作部(就是把一个大表里的一个小表提取出来)
然后生成了一个输出文件
数据分析很有意思
来源: http://www.jianshu.com/p/868bc7abf491