Issue
I am familiar with python but new to panda DataFrames. I have a dictionary like this:
a={'b':100,'c':300}
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!
Solution
Pass the values as a list:
a={'b':[100,],'c':[300,]}
pd.DataFrame(a)
b c
0 100 300
Or if for some reason you don't want to use a list, include an index:
a={'b':100,'c':300}
pd.DataFrame(a, index=['i',])
b c
i 100 300
Answered By - iayork
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.