Answer: Construct pandas DataFrame from items in nested dictionary

answer re: Construct pandas DataFrame from items in nested dictionary

Nov 27 ’12

153


This content originally appeared on DEV Community and was authored by Vicky Kumar

A pandas MultiIndex consists of a list of tuples. So the most natural approach would be to reshape your input dict so that its keys are tuples corresponding to the multi-index values you require. Then you can just construct your dataframe using pd.DataFrame.from_dict, using the option orient='index':

user_dict

image


This content originally appeared on DEV Community and was authored by Vicky Kumar


Print Share Comment Cite Upload Translate Updates
APA

Vicky Kumar | Sciencx (2021-06-24T09:25:18+00:00) Answer: Construct pandas DataFrame from items in nested dictionary. Retrieved from https://www.scien.cx/2021/06/24/answer-construct-pandas-dataframe-from-items-in-nested-dictionary/

MLA
" » Answer: Construct pandas DataFrame from items in nested dictionary." Vicky Kumar | Sciencx - Thursday June 24, 2021, https://www.scien.cx/2021/06/24/answer-construct-pandas-dataframe-from-items-in-nested-dictionary/
HARVARD
Vicky Kumar | Sciencx Thursday June 24, 2021 » Answer: Construct pandas DataFrame from items in nested dictionary., viewed ,<https://www.scien.cx/2021/06/24/answer-construct-pandas-dataframe-from-items-in-nested-dictionary/>
VANCOUVER
Vicky Kumar | Sciencx - » Answer: Construct pandas DataFrame from items in nested dictionary. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2021/06/24/answer-construct-pandas-dataframe-from-items-in-nested-dictionary/
CHICAGO
" » Answer: Construct pandas DataFrame from items in nested dictionary." Vicky Kumar | Sciencx - Accessed . https://www.scien.cx/2021/06/24/answer-construct-pandas-dataframe-from-items-in-nested-dictionary/
IEEE
" » Answer: Construct pandas DataFrame from items in nested dictionary." Vicky Kumar | Sciencx [Online]. Available: https://www.scien.cx/2021/06/24/answer-construct-pandas-dataframe-from-items-in-nested-dictionary/. [Accessed: ]
rf:citation
» Answer: Construct pandas DataFrame from items in nested dictionary | Vicky Kumar | Sciencx | https://www.scien.cx/2021/06/24/answer-construct-pandas-dataframe-from-items-in-nested-dictionary/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.