how to convert dictionary where values are stored in a list to df

Question:

I have a dictionary that I want to convert into DataFrame, the problem I’m having is my dictionary is in the following format:


sample_dict = {'test':['test string',['feature1','feature2', 'feature3']]}

When trying to convert using something like

df = pd.DataFrame.from_dict([sample_dict])

I get:

enter image description here

What I’m trying to achieve is something like:

enter image description here

Any ideas?

Asked By: mikelowry

||

Answers:

Add orient

out = pd.DataFrame.from_dict(sample_dict, orient='index')
Out[287]: 
                0                               1
test  test string  [feature1, feature2, feature3]
Answered By: BENY

Can use from_records as well.

df = pd.DataFrame.from_records(d).T

                0                               1
test  test string  [feature1, feature2, feature3]
Answered By: rafaelc
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.