zoukankan      html  css  js  c++  java
  • python批量处理excel文件数据

     

    https://www.zhihu.com/question/39299070?sort=created

    作者:水中柳影
    链接:https://www.zhihu.com/question/39299070/answer/81062665
    来源:知乎
    著作权归作者所有,转载请联系作者获得授权。
     
    该表列名:df.rename(columns={'原列名' : '新列名'})
    df1.ix[1:3,['merge_add']]  #取某一列的前3行

    excel的内容需要有规律,python才能按顺序读取出来。 比如按行按列读取。

    一、安装xlrd模块

    到python官网下载模块安装,前提是已经安装了python 环境。

    二、使用介绍

    1、导入模块

    import xlrd

    2、打开Excel文件读取数据

    data = xlrd.open_workbook('excelFile.xls')

    3、使用技巧

    获取一个工作表

    table = data.sheets()[0] #通过索引顺序获取

    table = data.sheet_by_index(0) #通过索引顺序获取

    table = data.sheet_by_name(u'Sheet1')#通过名称获取

    获取整行和整列的值(数组)

    table.row_values(i)

    table.col_values(i)

    获取行数和列数

    nrows = table.nrows

    ncols = table.ncols

    循环行列表数据

    for i in range(nrows ):

    print table.row_values(i)

    单元格

    cell_A1 = table.cell(0,0).value

    cell_C4 = table.cell(2,3).value

    使用行列索引

    cell_A1 = table.row(0)[0].value

    cell_A2 = table.col(1)[0].value

    简单的写入

    row = 0

    col = 0

    # 类型 0 empty,1 string, 2 number, 3 date, 4 boolean, 5 error

    ctype = 1 value = '单元格的值'

    xf = 0 # 扩展的格式化

    table.put_cell(row, col, ctype, value, xf)

    table.cell(0,0) #单元格的值'

    table.cell(0,0).value #单元格的值'

     
  • 相关阅读:
    android常用组件
    android button点击效果
    service+activity
    收藏
    c++
    工厂模式
    lr常遇到一些问题
    lr介绍
    ((1064, "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '(6) NOT NULL)' at line 1"))
    mysqlclient 1.4.0 or newer is required; you have 0.10.0
  • 原文地址:https://www.cnblogs.com/zhangbojiangfeng/p/6213918.html
Copyright © 2011-2022 走看看