doc_term_dict = {('d1', 't1'): 12, ('d2', 't3'): 10, ('d3', 't2'): 5}
rows = set([d for d, t in list(doc_term_dict.keys())])
cols = set([t for d, t in list(doc_term_dict.keys())])
df = DataFrame(index=rows, columns=cols)
df = df.fillna(0)
for key, value in list(doc_term_dict.items()):
    df[key[1]][key[0]] = value
print(df)
Generating a dense matrix from a sparse matrix in numpy python