[Python] 纯文本查看 复制代码 import pandas as pd
import numpy as np
#将表格数据转化成列表
def main(file_dj, file_dz, sheet_name):
a = file_dj
a1 = file_dz
b = pd.read_excel(a,sheet_name=sheet_name,dtype={"条形码":str})
b1 = pd.read_excel(a1,dtype={"条码":str})
b1=b1[['条码', '商家编码']]
# 调整条码字段为文
b1.columns=['条形码','商家编码']
# 将表格向下填充
df1 = b[b['操作结果'].isnull()]
df1['物流编号'] = df1['物流编号'].fillna(method='ffill')
# 2个表格根据条码进行做匹配
outer = pd.merge(df1,b1,on='条形码',how='left')
outer1=outer[outer['条形码'].isnull()|outer['货品数量'].notnull()]
df2 = outer1[outer1['货品数量'] != 0]
# 获取快递单号列表,并去重复
c = df2['物流编号'].values.tolist()
#print(len(c),c)
list_kd = list(set(c))
#print(list_kd)
#循环每个快递单号,获取所有的产品信息数据
y = []
for i in list_kd:
e = {}
p = {}
de = df2[df2['物流编号'] == i][['商家编码', '货品数量']].values.tolist()
for h in de:
p[h[0]] = h[1]
e['快递单号'] = i
e['data'] = p
y.append(e)
#print(y)
return (y)
def pd_nan(values_nan):
if values_nan is np.nan:
return 1
def shuliangcuowu(file_dj, sheet_name):
a=pd.read_excel(file_dj,sheet_name=sheet_name)
b=a[a['操作结果']=='数量错误']
c=b['物流编号'].values.tolist()
list_kd = list(set(c))
y = []
for i in list_kd:
e = {}
p = {}
de ={np.nan: 2}
e['快递单号'] = i
e['data'] = de
y.append(e)
#print(y)
return (y)
def rizhi(file_dj, sheet_name):
a=pd.read_excel(file_dj,sheet_name=sheet_name)
b=a[a['操作结果']=='无源单']
c=b[['物流编号',"操作结果"]].values.tolist()
return c |