1

I have a dictionary created run-time in my program which needs to be converted to a pandas dataframe.

dictio={'a':'abc','b':'zyx','c':'prq'} df=pd.Dataframe(dictio)

The above code returns me an empty dataframe with columns created. Can anyone point to what am i missing out?

1 Answer 1

3
#use from_dict and set orient to index and then transpose in the end.
pd.DataFrame.from_dict(dictio,orient='index').T
Out[263]: 
     a    c    b
0  abc  prq  zyx
Sign up to request clarification or add additional context in comments.

4 Comments

This works but I want the result to be in a transposed format, as in the dictionary keys should be column names.
Keys(a,b,c) are the column names here. What' your expected results?
I believe the example I have provided isn't enough, I have an empty dictionary set up with large number of columns whose values get set during the program. Converting into data-frame gives me using what was suggested dictionary keys as first column and 0 as another.
I'm not sure if I understand you problem. Please provide an example with more data and your desired output.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.