Converting a list of Dictionaries to dataframe about a key

Viewed 36

Is there a way to convert a list of dictionaries to a pandas dataframe for a single dictionary key?

Say, for sample_list = [{1:2.1, 2:4.5, 5:6.4}, {1:4.3, 2:5.4, 5:1}, {1:0.07, 2:9.5, 5:7.1}] The data frame would be

 2 
---
4.5 
5.4  
9.5    

where 2 is the column name.

EDIT:

Is there a way to rename the column and have something like

two
---
4.5 
5.4  
9.5    
1 Answers

You can specify columns= parameter when creating the dataframe:

df = pd.DataFrame(sample_list, columns=[2])
print(df)

Prints:

     2
0  4.5
1  5.4
2  9.5
Related