zoukankan      html  css  js  c++  java
  • Python处理Excel数据分组

    描述:将Excel表中的数据按照每50个进行分组,并输出保存到不同的文件。

     1 #coding=utf-8
     2 import xlrd
     3 
     4 def read(file):
     5     data = xlrd.open_workbook(file)
     6     table = data.sheets()[0]
     7     nrows = table.nrows
     8     ncols = table.ncols
     9     
    10 
    11     n = 0
    12     
    13     filename = 1
    14     fopen = open('d:/zemail/'+str(filename)+'.txt', 'w')
    15 
    16     for i in xrange(0, nrows):
    17         rowValues = table.row_values(i)
    18         n = n+1
    19         if n%51 != 0:
    20             for item in rowValues:
    21                 #print item
    22                 fopen.write(item+'
    ')
    23         else:
    24             fopen.close()
    25             filename = n
    26             fopen = open('d:/zemail/'+str(filename)+'.txt', 'w')
    27     fopen.close()
    28         
    29 
    30 #def create(filename):
    31     #if os.path.exists(fname):
    32         #print "File already exists!"
    33     #fopen = open(filename, 'w')
    34     #fopen.close()
    35 
    36 if __name__ == '__main__':
    37     path = "d:/email.xlsx"
    38     read(path)
  • 相关阅读:
    菜鸟的it之路-起航
    实验报告四
    实验报告三
    实验报告二
    实验报告一
    远程连接
    操作系统安装
    服务器硬件组成
    linux系统下排查cpu过高原因
    windows系统下排查Java项目cpu过高原因
  • 原文地址:https://www.cnblogs.com/seasondaily/p/8623574.html
Copyright © 2011-2022 走看看