converting array to a true/false matrices I have a data set where each record is a json document with a label, and an array of signals. The signals will vary for each record:
{
    &quot;label&quot;:&quot;bad&quot;,
    &quot;id&quot;: &quot;0009&quot;,
    &quot;signals&quot;:[&quot;high_debt_ratio&quot;, &quot;no_job&quot;] 
},

{
    &quot;label&quot;:&quot;good&quot;,
     &quot;id&quot;: &quot;0002&quot;,
    &quot;signals&quot;:[&quot;high_debt_ratio&quot;, &quot;great_credit&quot;, &quot;no_id_match&quot;] 
},

{
    &quot;label&quot;:&quot;good&quot;,
    &quot;id&quot;: &quot;0003&quot;,
    &quot;signals&quot;:[&quot;low_debt_ratio&quot;, &quot;great_credit&quot;] 
},

{
    &quot;label&quot;:&quot;bad&quot;,
    &quot;id&quot;: &quot;0001&quot;,
    &quot;signals&quot;:[&quot;high_risk_loc&quot;, high_debt_ratio&quot;, &quot;no_job&quot;, &quot;no_id_match&quot;] 
}

I want to convert this to a matrices that looks like this:




id
label
high_risk_loc
high_debt_ratio
no_job
great_credit
no_id_match
low_debt_ratio




0009
bad
false
true
true
false
false
false


0002
good
false
true
false
true
true
false


0003
good
false
false
false
true
false
true


0001
bad
true
true
true
false
true
false




I created a function but it seems like this would be a common thing to do. Is there a python lib (pandas, scikit, etc.) that does this for you? I'd rather use something from a package but i'm not sure what to search for.
You can try this one line solution:
d = pd.json_normalize([{
    &quot;label&quot;:&quot;bad&quot;,
    &quot;id&quot;: &quot;0009&quot;,
    &quot;signals&quot;:[&quot;high_debt_ratio&quot;, &quot;no_job&quot;] 
},

{
    &quot;label&quot;:&quot;good&quot;,
     &quot;id&quot;: &quot;0002&quot;,
    &quot;signals&quot;:[&quot;high_debt_ratio&quot;, &quot;great_credit&quot;, &quot;no_id_match&quot;] 
},

{
    &quot;label&quot;:&quot;good&quot;,
    &quot;id&quot;: &quot;0003&quot;,
    &quot;signals&quot;:[&quot;low_debt_ratio&quot;, &quot;great_credit&quot;] 
},

{
    &quot;label&quot;:&quot;bad&quot;,
    &quot;id&quot;: &quot;0001&quot;,
    &quot;signals&quot;:[&quot;high_risk_loc&quot;, &quot;high_debt_ratio&quot;, &quot;no_job&quot;, &quot;no_id_match&quot;] 
}])

d.merge(d.signals.apply(lambda x: &quot;|&quot;.join(x)).str.get_dummies(sep = &quot;|&quot;), left_index = True, right_index= True)

Outputs: