Convert tuple and nested dictionary to DataFrame
One possible way to do it:
import pandas as pd
d = {0: ('Product', {'0': 'Smartwatch', '1': 'Shoes', '2': 'Necklace'}),
1: (' Weight', {'0': 2, '1': 50, '2': 40}),
2: (' Price', {'0': 100, '1': 240, '2': 230})}
d_col = {}
df = pd.DataFrame()
idx = 0
for k,v in d.items():
d_col[k] = v[0]
df = df.append(pd.DataFrame(data=v[1],index=[idx]))
idx+=1
df = df.T.rename(columns = d_col)
print(df)
I break the tuple up and manipulate the information as needed. First, to make a dictionary called d_col. I append the data we want to an initially empty DataFrame and keep appending. Later, I use the dictionary d_col in order to label the df.T with the correct column names based on index, as I had set these indices based on idx earlier in the loop.
Output:
Product Weight Price
0 Smartwatch 2 100
1 Shoes 50 240
2 Necklace 40 230