pd Excel操作

import pandas as pd
import time
print(“转化开始”)
t0 = time.clock()
excelname = “PREDICTEDDATA20216-8(1).xls”
sheet0 = pd.read_excel(excelname, sheet_name =0)
sheet1 = pd.read_excel(excelname, sheet_name =1)
SLAB_NO = sheet1[“SLAB_NO”]
sheet1IDdic = {}
for Sindex,Svalue in SLAB_NO.items():
if not pd.isnull(Svalue):
sheet1IDdic[int(Svalue)] = Sindex

print(sheet1IDdic)

hangshu = sheet0.iloc[:,0].size
for i in range(hangshu):
SLAB_NO_Value = sheet0.iloc[i, 0]
if not pd.isnull(SLAB_NO_Value):
if SLAB_NO_Value in sheet1IDdic:
sheet1Index = sheet1IDdic[SLAB_NO_Value]
# print(“SLAB_NO_Value”, SLAB_NO_Value)
sheet0.iloc[i, 4] = sheet1.iloc[sheet1Index, 1]
sheet0.iloc[i, 5] = sheet1.iloc[sheet1Index, 2]
sheet0.iloc[i, 6] = sheet1.iloc[sheet1Index, 3]
sheet0.iloc[i, 7] = sheet1.iloc[sheet1Index, 4]

filename = “new”
writer = pd.ExcelWriter(filename + ‘.xlsx’)
sheet0.to_excel(writer, index=False)#index=False,header=None)
writer.save()
writer.close()
print(“转化成功,耗时:”,time.clock() - t0)
#2110211445 2110211447 2110493234

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值