I have a dictionary like below,
{'A': 0, 'C': 0, 'B': 1, 'E': 3, 'D': 1, 'G': 0, 'F': 0, 'I': 3, 'H': 3, 'J': 1}
using this dictionary I want to create a pandas data frame like below,
A B C D E F G H I J
0 1 0 1 0 0 1 1 0 0 0
1 0 1 0 1 0 0 0 0 0 1
2 0 0 0 0 0 0 0 0 0 0
3 0 0 0 0 1 0 0 1 1 0
the above dictionary's key - value pair represent column name - index using this value I want to create a data frame like above.
for example 'A': 0
represents columns A at 0th index value should be one similarly 'E': 3,
represents columns E at 3rd index value should be one.
So far I tried this,
df=pd.DataFrame(index=range(max(my_dic.values())),columns=[req_cols])
for u,v in my_dic.items():
df.at[v,u]=1
print df.fillna(0)
Above code works fine, But I think it's not a effective way to solve this problem. Is there any better effective approach to solve this problem?
any help would be really appreciable.
Thanks in Advance.