Python Forum
Normalize table (remove redundancy)
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Normalize table (remove redundancy)
#1
Hi everyone,

I have a excel table like this:


CODE | MATRIX | SAMPLING | FREQUENCY | PARAM
XX123 | OG | spot | 14 | 99
XX123 | OG | spot | 14 | 50
XX123 | OG | spot | 14 | 1620
AB006 | OG | mix | 28 | 3
AB006 | OG | mix | 28 | 4005


Can I somehow normalize this data to a list of dictionaries like this?:
[[ {'CODE': 'XX123', 'MATRIX': 'OG', 'SAMPLING':'spot', 'FREQUENCY':14, 'PARAM':[99, 50, 1620]},
{'CODE': 'AB006', 'MATRIX': 'OG', 'SAMPLING':'mix', 'FREQUENCY':28, 'PARAM':[3, 4005]} ]
I tried googling this problem but didn't come across an exact match.

Thanks in advance
Markus
Reply
#2
Is it possible to change the layout of the dictionary so the key is comprised of ('CODE ', ' MATRIX ', ' SAMPLING ', ' FREQUENCY '). This would make it much simpler to build up the values of the last column.
It would look like this:
Output:
{ ('CODE ', ' MATRIX ', ' SAMPLING ', ' FREQUENCY '): [' PARAM'], ('XX123 ', ' OG ', ' spot ', ' 14 '): [' 99', ' 50', ' 1620'], ('AB006 ', ' OG ', ' mix ', ' 28 '): [' 3', ' 4005'] }
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020