excel处理

s1,s2,s3,s4,s5,s6,s7 = [],[],[],[],[],[],[] 
def process_one(path):
 df = pd.read_excel(path)
 data = list(df.values)
 if len(list(data[0])) != 7:
  print(path)
  return

 for tem in data:
  tem_list =list(tem)
  s1.append(tem_list[0])
  s2.append(tem_list[1])
  s3.append(tem_list[2])
  s4.append(tem_list[3])
  s5.append(tem_list[4])
  s6.append(tem_list[5])
  s7.append(tem_list[6])
 for idx in range(6):
  s1.append('')
  s2.append('')
  s3.append('')
  s4.append('')
  s5.append('')
  s6.append('')
  s7.append('')
path = "1.县(市)社会经济主要指标/"
for tem in os.listdir(path):
 process_one(path + tem)


pd.DataFram({"1":s1,'2':s2,'3':s3,'4':s4,'5':s5,'6':s6,'7':s7}).to_excel("res.xlsx")

 

import msoffcrypto

s1,s2,s3,s4,s5,s6,s7 = [],[],[],[],[],[],[] 
def process_one(path):
 try:
    df = pd.read_excel(path, errors='ignore')
 except:
    print(path)
    return
 data = list(df.values)
 if len(list(data[0])) != 7:
  print(path)
  return

 for tem in data:
  tem_list =list(tem)
  s1.append(tem_list[0])
  s2.append(tem_list[1])
  s3.append(tem_list[2])
  s4.append(tem_list[3])
  s5.append(tem_list[4])
  s6.append(tem_list[5])
  s7.append(tem_list[6])
 for idx in range(6):
  s1.append('')
  s2.append('')
  s3.append('')
  s4.append('')
  s5.append('')
  s6.append('')
  s7.append('')
path = "20220724/2013/"
import os
import pandas as pd
for tem in os.listdir(path):
 
 file = msoffcrypto.OfficeFile(open(path + tem, 'rb'))
 file.load_key(password='VelvetSweatshop')
 path_ = (path + tem).replace("xls", "xlsx")
 os.popen("rm -rf " + path + tem).readlines()
 file.decrypt(open(path_, 'wb'))

 process_one(path_)


pd.DataFrame({"1":s1,'2':s2,'3':s3,'4':s4,'5':s5,'6':s6,'7':s7}).to_excel("2013.xlsx")

 

import msoffcrypto
import os
import pandas as pd

def process_one(path):
   df = pd.read_excel(path, errors='ignore')
   tem_list = list(df.values)
   row = len(tem_list)
   col = len(tem_list[0])
   i = 0
   while i < col:
      for j in range(row):
         s1.append(tem_list[j][i] if i < col else '')
         s2.append(tem_list[j][i+1] if i+ 1 < col else '')
         s3.append(tem_list[j][i+2] if i + 2 < col else '')
         s4.append(tem_list[j][i+3] if i + 3 < col else '')
         s5.append(tem_list[j][i+4] if i + 4 < col else '')
         s6.append(tem_list[j][i+5] if i + 5 < col else '')
         s7.append(tem_list[j][i+6] if i + 6 < col else '')
      i = i + 9
      if i >= col:
         break

      for _ in range(6):
         s1.append('')
         s2.append('')
         s3.append('')
         s4.append('')
         s5.append('')
         s6.append('')
         s7.append('')


for year in range(2008,2013):
   path = "20220724/" + str(year) + "/"
   s1,s2,s3,s4,s5,s6,s7 = [],[],[],[],[],[],[]
   for tem in os.listdir(path):

      file = msoffcrypto.OfficeFile(open(path + tem, 'rb'))
      file.load_key(password='VelvetSweatshop')
      path_ = (path + tem).replace("xls", "xlsx")
      os.popen("rm -rf " + path + tem).readlines()
      file.decrypt(open(path_, 'wb'))

      process_one(path_)
   pd.DataFrame({"1":s1,'2':s2,'3':s3,'4':s4,'5':s5,'6':s6,'7':s7}).to_excel(str(year) + ".xlsx")

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值