Mario Parreño Mario Parreño -4 years ago 128
Python Question

Tuple key Dictionary to Table/Graph 3-dimensional

I have a dictionary like this:

dict = {(100,22,123):'55%',(110,24,123):'58%'}

Where, for example, the elements of the tuple are (x,y,z) and the value is the error rate of something... I want to print that dictionary but I'm not very clear how to do it or in what format to do it (which would be better to see easily the information, maybe: x - y - z - Rate ).

I found that: Converting Dictionary to Dataframe with tuple as key ,but I think it does not fit what I want and I can not understand it.

Thank you

Answer Source

You can use Series with reset_index, last only set new column names:

import pandas as pd
d = {(100,22,123):'55%',(110,24,123):'58%'}
df = pd.Series(d).reset_index()
df.columns = ['a','b','c', 'd']
print (df)
     a   b    c    d
0  100  22  123  55%
1  110  24  123  58%
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download