Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

nested dict to df

user_dict = {12: {'Category 1': {'att_1': 1, 'att_2': 'whatever'},
                  'Category 2': {'att_1': 23, 'att_2': 'another'}},
             15: {'Category 1': {'att_1': 10, 'att_2': 'foo'},
                  'Category 2': {'att_1': 30, 'att_2': 'bar'}}}

pd.DataFrame.from_dict({(i,j): user_dict[i][j] 
                           for i in user_dict.keys() 
                           for j in user_dict[i].keys()},
                       orient='index')


               att_1     att_2
12 Category 1      1  whatever
   Category 2     23   another
15 Category 1     10       foo
   Category 2     30       bar
Comment

PREVIOUS NEXT
Code Example
Python :: django admin image 
Python :: python faker 
Python :: show a image in python 
Python :: pandas merge multiple dataframes 
Python :: openpyxl write in cell 
Python :: grassmann formula 
Python :: pandas series sort 
Python :: python list comprehension double for 
Python :: python dataframe column string to integer python 
Python :: loop rought rows in pands 
Python :: scatter plot plotly 
Python :: sys get current pythonpath 
Python :: convert two numpy array to pandas dataframe 
Python :: Python find inverse of matrix 
Python :: python lowercase 
Python :: save pythonpath 
Python :: Python pandas drop any row 
Python :: activate venv enviroment 
Python :: python import ndjson data 
Python :: rightclick in pygame 
Python :: mark_safe django 
Python :: python print without leading whitespace 
Python :: say command python 
Python :: what is values_list in django orm 
Python :: how to print variables in a string python 
Python :: python csv read header only 
Python :: limpiar consola en python 
Python :: proper tree in data structure 
Python :: max of matrix numpy 
Python :: what is need of bias in NN 
ADD CONTENT
Topic
Content
Source link
Name
6+9 =