Skip to content
Advertisement

Create Python DataFrame from dictionary where keys are the column names and values form the row

I am familiar with python but new to panda DataFrames. I have a dictionary like this:

JavaScript

And I would like to convert it to a DataFrame, where b and c are the column names, and the first row is 100,300 (100 is underneath b and 300 is underneath c). I would like a solution that can be generalized to a much longer dictionary, with many more items. Thank you!

Advertisement

Answer

Pass the values as a list:

JavaScript

Or if for some reason you don’t want to use a list, include an index:

JavaScript
User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement