python - Read Excel and convert it into a nested dictionary -


i have excel file structure this

name age status anna 35 single petr 27 married 

is there generic way convert such excel file nested dictionary structure this

{'anna': {'age':35}, {'status': 'single'}}, {'petr': {'age':27}, {'status': 'married'}} 

should first import excel file , convert pandas dataframe , create nested dictionary or exist straight way of importing excel sheet , creating such dictionary?

the output asking isn't valid python data strcture.

you can achieve similar df.to_dict:

import pandas pd  df = pd.read_excel('path/to/file') df.set_index('name',  inplace=true) print(df.to_dict(orient='index')) # {'petr': {'age': 27, 'status': 'married'}, 'anna': {'age': 35, 'status': 'single'}} 

Comments

Popular posts from this blog

python Tkinter Capturing keyboard events save as one single string -

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

javascript - Z-index in d3.js -