Home > other >  Consult reading excel table data and will be the same data as a whole the merger of a dictionary how
Consult reading excel table data and will be the same data as a whole the merger of a dictionary how

Time:03-22

I have an excel spreadsheet, wants to retrieve the customer data into the database, now the problem is in some parts of the cell data is repeated, after I read it out don't know how to merge into a dictionary, excel spreadsheet data are as follows:

To generate a dictionary format:
 : supplier=[{
'name' : 'creative digital technology co., LTD.,
'province' : 'in guangdong,
'city' : 'shenzhen',
'contact' : 'Zhang Sanfeng',
'phone', '13800000000',
'the product: [
{' product_name ':' office stationery ', 'sub' : [{' name ':' pen ', 'price', '3', 'unit' : 'a'}, {' name ':' paper ', 'price' : '30', 'unit' : 'package'}, {' name ':' notepad ', 'price' : '4.5', 'unit' : 'this'}],
{' product_name ':' computer ', 'sub' : [{' name ':' laptop ', 'price', '5800', 'unit' : 'units'}]}
]
},
{
'name' : 'ABC',
'province' : 'Shanghai',
'city' : ' ',
'contact' : 'Reese Cathy',
'phone', '87900000',
'the product: [
{' product_name ':' instructions sheet ', 'sub' : [{' name ':' the prophase planning, 'price', '1000', 'unit' : 'set'}, {' product_name ':' real estate marketing piece, 'sub' : [{' name ':' the prophase planning, 'price' : '3000', 'unit' : 'set'}]}
]
},
]

CodePudding user response:

Read excel to list
Traverse the list
Set up three layers of nested dictionaries,
List the inner value of the dictionary is traversed to determine whether a list, if there is append


Looks like this,
  • Related