Commit 902d0b56 by larosa

write to xlsx

parent a0316310
Showing with 27 additions and 5 deletions
......@@ -74,14 +74,14 @@ black_list = {"eastsheep", "ABB", "BRsanyuan", "JCSTRONG", "TECHNOLOGY",
}
count = 0
# 如果是采用单线程的模式跑这个脚本,解析完4000多行数据恐怕要1个小时了 所以还是采用多进程的方式吧 用四个脚本同时解析一个文件的不同行
def main():
df = pd.read_excel('table.xlsx')
data = df.iloc[:, [0]].values
ans = []
result = []
for i in range(len(data)):
if i > 10:
if i >= 1000:
break # for debug, don't forget to delete this line.
sku_name_str = data[i][0]
res_tmp = match_sku(sku_name_str)
......@@ -97,6 +97,8 @@ def main():
if len(tmp_map) != 0:
score_in_one_row.append(tmp_map)
if len(score_in_one_row) == 0:
result.append({})
print(i, "------", {})
continue
else:
max_score = score_in_one_row[0].get("score")
......@@ -106,7 +108,8 @@ def main():
max_score = score_in_one_row[k].get("score")
index = k
result.append(score_in_one_row[index])
return result
print(i, "------", score_in_one_row[index])
return result #返回一个列表,列表中要么为空字典,要么为 {"goods_name": _goods_name, "goods_id": _goods_id, "brand_name": _brand_name, "score": _score} 字典
def match_sku(s: str) -> []:
# s = "RG58/U射频连接线SMA公头转BNC公头延长线 SMA/BNC-JJ Q9/SMA-JJ RG58/U-SMA/BNC-JJ 2m"
......@@ -154,6 +157,25 @@ def process(query_str: dict):
return {}
def write_to_xlsx(info_map_list: list):
table = {'goods_name': [], 'goods_id': [], 'brand_name': []}
for i in range(len(info_map_list)):
if len(info_map_list[i]) != 0:
table["goods_name"].append(info_map_list[i]["goods_name"])
table["goods_id"].append(str(info_map_list[i]["goods_id"]))
table["brand_name"].append(info_map_list[i]["brand_name"])
else:
table["goods_name"].append('')
table["goods_id"].append('')
table["brand_name"].append('')
df = pd.DataFrame(table)
df.to_excel('table.xlsx', sheet_name='Sheet1', index=False, startcol=3)
if __name__ == '__main__':
res = main()
print(res)
\ No newline at end of file
# this is how to write to xlsx file, don't delete it !!
# df = pd.DataFrame({'One': ['', 'test123', ''], 'Two': ['qq', 'mr', 'asd']})
# df.to_excel('ans.xlsx', sheet_name='Sheet1', index=False, startcol=3)
write_to_xlsx(res)
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment