python dict to dataframe


http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.from_dict.html

 

 

Examples

By default the keys of the dict become the DataFrame columns:

>>> data = {'col_1': [3, 2, 1, 0], 'col_2': ['a', 'b', 'c', 'd']} >>> pd.DataFrame.from_dict(data)  col_1 col_2 0 3 a 1 2 b 2 1 c 3 0 d 

Specify orient='index' to create the DataFrame using dictionary keys as rows:

>>> data = {'row_1': [3, 2, 1, 0], 'row_2': ['a', 'b', 'c', 'd']} >>> pd.DataFrame.from_dict(data, orient='index')  0 1 2 3 row_1 3 2 1 0 row_2 a b c d 

When using the ‘index’ orientation, the column names can be specified manually:

>>> pd.DataFrame.from_dict(data, orient='index', ... columns=['A', 'B', 'C', 'D'])  A B C D row_1 3 2 1 0 row_2 a b c d 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM