Skip to content Skip to sidebar Skip to footer

Python Dict To Dataframe Pandas - Levels

Few months ago @Romain X. helped me a lot with this question: Python dict to DataFrame Pandas Now I´m trying to do the same with deeper levels, here is the example: {u'instrumen

Solution 1:

Here you go,

df = pd.DataFrame.from_dict(d)\
.join(pd.DataFrame.from_dict(d['instruments']))\
.drop('instruments', axis=1)

df2 = pd.DataFrame.from_dict(df.interestRate[0])
df2 = pd.DataFrame.transpose(df2)
df2 = df2.reset_index()
df2.columns.values[0] = 'instrument'

print (df2)

  instrument    ask  bid
0        EUR  0.004  0.0
1        USD  0.004  0.0

Post a Comment for "Python Dict To Dataframe Pandas - Levels"