Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
岳巧源
/
my-awesome-project
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
902d0b56
authored
Jun 20, 2024
by
larosa
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
write to xlsx
parent
a0316310
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
27 additions
and
5 deletions
main.py
main.py
View file @
902d0b56
...
...
@@ -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
>
1
0
:
if
i
>
=
100
0
:
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
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment