Python List Excel 改单列表合并为一条
作者:互联网
改单列表合并为一条
# 改单列表合并为一条
def changeBillMerge(t):
# 按主键第一顺序 时间第二顺序 倒序排序
t = sorted(t, key=(lambda x: [x[0], x[7]]), reverse=True)
new_list = []
new_list.append(["录入时间", "托单号", "查货编号", "揽货站点", "到站", "货到站点", "发货方", "发货联系人", "发货手机", "发货电话", "发货单位", "发货地址", "收货人", "收货手机","收货单位", "收货地址", "收货电话", "货名", "包装", "件数", "重量(t)", "体积", "货值", "保费含", "单价", "已付", "支付方式", "欠付","打卡","到付", "回付", "月付", "货款抵扣", "代收货款", "运费", "费用总计", "预算差额", "现返", "欠返", "送货费含", "提货费含", "装卸费含","垫付运费", "上楼费含", "录入人名", "送提", "备注", "回执单号", "回执数", "托单日期", "托单状态", "预算其他", "预算送货", "预算中转", "手续费到付", "手续费欠付","手续费现付"])
for i in range(len(t)):
# print(t[i][0],'\t',t[i][7])
# 提取修改记录
t5list = t[i][5].split(";")
t5list = [j for j in t5list if j != ''] # 删除空元素
# 分析修改数据,解析具体内容为多单号list
for x in t5list:
tlist = []
for x1 in range(57): tlist.append("")
tlist[1], tlist[0], tlist[49] = t[i][0], t[i][7], t[i][7][:10]
# print(x, end="\t")
x0 = x.split("【")[0]
if x0 == "托单号":
tlist[1] = x.split("改为【")[1][:-1]
elif x0 == "到站":
tlist[4] = x.split("改为【")[1][:-1]
elif x0 == "货到站点":
tlist[5] = x.split("改为【")[1][:-1]
elif x0 == "发货方":
tlist[6] = x.split("改为【")[1][:-1]
elif x0 == "发货人":
tlist[7] = x.split("改为【")[1][:-1]
elif x0 == "发货人手机":
tlist[8] = x.split("改为【")[1][:-1]
elif x0 == "收货人":
tlist[12] = x.split("改为【")[1][:-1]
elif x0 == "收货人手机":
tlist[13] = x.split("改为【")[1][:-1]
elif x0 == "收货地址":
tlist[15] = x.split("改为【")[1][:-1]
elif x0 == "货名":
tlist[17] = x.split("改为【")[1][:-1]
elif x0 == "包装":
tlist[18] = x.split("改为【")[1][:-1]
elif x0 == "件数":
tlist[19] = x.split("改为【")[1][:-1]
elif x0 == "重量":
tlist[20] = x.split("改为【")[1][:-1]
elif x0 == "体积":
tlist[21] = x.split("改为【")[1][:-1]
elif x0 == "保费含":
tlist[23] = x.split("改为【")[1][:-1]
elif x0 == "已付":
tlist[25] = x.split("改为【")[1][:-1]
elif x0 == "欠付":
tlist[27] = x.split("改为【")[1][:-1]
elif x0 == "打卡":
tlist[28] = x.split("改为【")[1][:-1]
elif x0 == "到付":
tlist[29] = x.split("改为【")[1][:-1]
elif x0 == "回付":
tlist[30] = x.split("改为【")[1][:-1]
elif x0 == "月付":
tlist[31] = x.split("改为【")[1][:-1]
elif x0 == "代收货款":
tlist[33] = x.split("改为【")[1][:-1]
elif x0 == "运费":
tlist[34] = x.split("改为【")[1][:-1]
elif x0 == "现返":
tlist[37] = x.split("改为【")[1][:-1]
elif x0 == "欠返":
tlist[38] = x.split("改为【")[1][:-1]
elif x0 == "送货含":
tlist[39] = x.split("改为【")[1][:-1]
elif x0 == "提货含":
tlist[40] = x.split("改为【")[1][:-1]
elif x0 == "装卸含":
tlist[41] = x.split("改为【")[1][:-1]
elif x0 == "上楼含":
tlist[43] = x.split("改为【")[1][:-1]
# elif x0 == "其他含":
# tlist[18] = x.split("改为【")[1][:-1]
elif x0 == "录单人姓名":
tlist[44] = x.split("改为【")[1][:-1]
elif x0 == "送货方式":
tlist[45] = x.split("改为【")[1][:-1]
elif x0 == "备注说明":
tlist[46] = x.split("改为【")[1][:-1]
elif x0 == "回执数":
tlist[48] = x.split("改为【")[1][:-1]
elif x0 == "托单日期":
tlist[49] = t[i][7][:10] # 此处注意 是改单录入时间
else:
print("<<<<-----",x0, end="\t")
print(x.split("改为【")[1][:-1],"-----<<<< 未收录数据",)
new_list.append(tlist)
# print("-----------%d------------" % i)
# 将多单号合并为一个单号
tlist = []
for i in range(len(new_list)):
# 第一行直接复制
if i == 0 :
tlist.append(new_list[i])
continue
# 第二行 和前一行单号不同 直接复制 单号相同 合并
if new_list[i][1] != new_list[i-1][1]:
tlist.append(new_list[i])
else:
for j in range(len(new_list[i])):
if new_list[i][j]:
tlist[-1][j] = new_list[i][j]
# print(tlist[:16])
# print(len(tlist))
return tlist
标签:elif,Python,Excel,改为,split,发货,tlist,x0,改单 来源: https://www.cnblogs.com/cbig/p/13967468.html