I have a list of strings below. It's a simple example for now, with just 3 strings, and each string contains some keys and their corresponding values. For example, string 1 says that expiration year is 2024, birth year is 1947, issue year is 2015, height is 150 cm, etc.
show q4
"eyr:2024 pid:662406624 hcl:#cfa07d byr:1947 iyr:2015 ecl:amb hgt:150cm"
"iyr:2013 byr:1997 hgt:182cm hcl:#ceb3a1 eyr:2027 ecl:gry cid:102 pid:018128"
"hgt:61in iyr:2014 pid:916315544 hcl:#733820 ecl:oth"
From this other thread, terrylynch explained to me that I can use a built-in kdb/q function to extract the key-value pairs as dictionaries kdb/q: How to apply a string manipulation function to a vector of strings to output a vector of strings?
dict: each["S: "0:] q4
dict[0]
eyr pid hcl byr iyr ecl hgt
"2024" "662406624" "#cfa07d" "1947" "2015" "amb" "150cm"
Then I tried to convert this into a table. Conceptually, I understand that kdb/q tables are basically flipped dictionaries and I understand that a table's rows are basically just dictionaries.
t: flip dict
show t
`eyr`pid`hcl`byr`iyr`ecl`hgt `iyr`byr`hgt`hcl`e..
("2024";"662406624";"#cfa07d";"1947";"2015";"amb";"150cm") ("2013";"1997";"18..
show t[0]
`eyr`pid`hcl`byr`iyr`ecl`hgt
`iyr`byr`hgt`hcl`eyr`ecl`cid`pid
`hgt`iyr`pid`hcl`ecl
show t[1]
("2024";"662406624";"#cfa07d";"1947";"2015";"amb";"150cm")
("2013";"1997";"182cm";"#ceb3a1";"2027";"gry";"102";"018128")
("61in";"2014";"916315544";"#733820";"oth")
The issue here is that this above table has different columns for each row. How do I get this table to look something like this below, where the table columns are the union of all of the keys and where a row has missing values for a key, it just shows null?
show ideal_t
eyr iyr pid cid..
---------------------------..
2024 2015 662406624 0n ..
2027 2013 018128 102..
Thanks!