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
b2056aa8
authored
Jul 30, 2024
by
larosa
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
resolve
parent
d7fd8c93
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
47 additions
and
10 deletions
waldom_data_process_RMB.py
waldom_data_process_RMB.py
View file @
b2056aa8
import
csv
import
json
import
logging
import
time
import
openpyxl
import
pandas
as
pd
...
...
@@ -21,22 +24,49 @@ title_arr = [
'Price Break Qty 3'
,
'Price Break 3'
,
'Price Break Qty 4'
,
'Price Break 4'
,
'Price Break Qty 5'
,
'Price Break 5'
,
'Price Break Qty 6'
,
'Price Break 6'
,
'Price Break Qty 7'
,
'Price Break 7'
,
'Price Break Qty 8'
,
'Price Break 8'
,
'Price Break Qty 9'
,
'Price Break 9'
'Price Break Qty 9'
,
'Price Break 9'
,
'Date Code'
]
ladder_map
=
{
'Price Break Qty 1'
:
'Price Break 1'
,
'Price Break Qty 2'
:
'Price Break 2'
,
'Price Break Qty 3'
:
''
,
'Price Break Qty 4'
,
'Price Break Qty 5'
,
'Price Break Qty 6'
,
'Price Break Qty 7'
,
'Price Break Qty 8'
,
'Price Break Qty 9'
,
}
class
HandleCSV
:
def
parse
(
self
,
path
):
df
=
pd
.
read_excel
(
path
,
nrows
=
0
)
first_row
=
[]
for
i
in
range
(
len
(
df
.
columns
)):
print
(
df
.
columns
[
i
])
first_row
.
append
(
df
.
columns
[
i
])
if
not
self
.
validate
(
first_row
):
df
=
pd
.
read_excel
(
path
,
sheet_name
=
0
)
if
not
self
.
validate
(
df
.
columns
.
values
):
logger
.
error
(
"文件
%
s 格式错误"
%
path
)
return
[]
data
=
pd
.
read_excel
(
path
,
title_arr
)
print
(
data
.
values
())
for
i
in
range
(
len
(
df
.
index
.
values
)):
# print(df.loc[i, title_arr[0]])
table
=
dict
()
for
j
in
range
(
len
(
title_arr
)):
ladder_item_map
=
dict
()
data
=
df
.
loc
[
i
,
title_arr
[
j
]]
if
title_arr
[
j
]
==
'Manufacturer Name'
:
table
[
'brand_name'
]
=
data
elif
title_arr
[
j
]
==
'Part Number'
:
table
[
'goods_name'
]
=
data
elif
title_arr
[
j
]
==
'Stock EMEA'
or
\
title_arr
[
j
]
==
'Stock USA'
or
\
title_arr
[
j
]
==
'Stock APAC'
or
\
title_arr
[
j
]
==
'Stock CN'
:
if
len
(
str
(
data
)
.
strip
())
>
0
:
if
'stock'
in
table
:
table
[
'stock'
]
+=
int
(
data
)
else
:
table
[
'stock'
]
=
int
(
data
)
elif
title_arr
[
j
]
==
'MOQ'
:
table
[
'moq'
]
=
data
elif
title_arr
[
j
]
in
ladder_map
:
ladder_item_map
[
'purchases'
]
=
int
(
data
)
ladder_item_map
[
'price_us'
]
=
float
(
0
)
ladder_item_map
[
'price_cn'
]
=
float
()
...
...
@@ -49,9 +79,16 @@ class HandleCSV:
count
+=
1
return
count
==
size
def
generate_json
(
self
,
):
pass
if
__name__
==
'__main__'
:
start
=
time
.
time
()
HandleCSV
()
.
parse
(
'Tianyang_Inventory_Feed_RMB.xlsx'
)
end
=
time
.
time
()
print
(
"spend time: "
+
str
(
end
-
start
))
...
...
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