I have the following pandas dataframe:
| name | score |
|---|---|
[A, B, C] |
[1, 2, 0] |
[A, B] |
[1, 0] |
[B, D] |
[2, 0] |
[A, B, C, D] |
[1, 2,3,4] |
I would like to get the following pandas dataframe:
| A | B | C | D |
|---|---|---|---|
| 1 | 2 | 0 | NA |
| 1 | 0 | NA | NA |
| NA | 2 | NA | 0 |
| 1 | 2 | 3 | 4 |
So far, I have done the following:
l_df = []
for i in range(len(df)):
df_ = pd.DataFrame(data = [df.iloc[i]['score']], columns = df.iloc[i]['name'])
l_df.append(df_)
pdf_risk_all = pd.concat(l_df)
However, this takes a long time and it's not good for a dataset with >1MM rows. Any suggestions to do this in a more efficient way?
Thank you,