Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Dictionary of Lists into DataFrame

d = {"name: "name1", "key1" : ["A", "B"], "key2": ["C"]}
and I want to create DataFrame with 1 row and columns name, key1 and key2 with values respectively name1,["A", "B"] and ["C"]

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

One way is to create it with index orientation then transpose it.

import pandas as pd

d = {"name": "name1", "key1" : ["A", "B"], "key2": ["C"]}
df = pd.DataFrame.from_dict(d, orient='index').transpose()
print(df)

Output:

    name    key1 key2
0  name1  [A, B]  [C]
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading