Answers for "convert dict of dict to dataframe"

22

pandas dataframe from dict

data = {'col_1': [3, 2, 1, 0], 'col_2': ['a', 'b', 'c', 'd']}
pd.DataFrame.from_dict(data)
Posted by: Guest on March-30-2020
1

create pandas dataframe from dictionary

In [11]: pd.DataFrame(d.items())  # or list(d.items()) in python 3
Out[11]:
             0    1
0   2012-07-02  392
1   2012-07-06  392
2   2012-06-29  391
3   2012-06-28  391
...

In [12]: pd.DataFrame(d.items(), columns=['Date', 'DateValue'])
Out[12]:
          Date  DateValue
0   2012-07-02        392
1   2012-07-06        392
2   2012-06-29        391
Posted by: Guest on May-01-2021
2

python How to convert a dictionary of dictionaries nested dictionary to a Pandas dataframe

# Basic syntax:
dataframe = pd.DataFrame(nested_dictionary)
dataframe = dataframe.transpose()

# Note, this only works if your nested dictionaries are set up in a 
# 	specific way. See below. 

# Create nested dictionary:
import pandas as pd
student_data = { 
0 : {
    'name' : 'Aadi',
    'age' : 16,
    'city' : 'New york'
    },
1 : {
    'name' : 'Jack',
    'age' : 34,
    'city' : 'Sydney'
    },
2 : {
    'name' : 'Riti',
    'age' : 30,
    'city' : 'Delhi'
    }
}

# Example usage:
pandas_dataframe = pd.DataFrame(student_data) 
print(pandas_dataframe)
             0       1      2 # Outer keys become column names
age         16      34     30
city  New york  Sydney  Delhi
name      Aadi    Jack   Riti

pandas_dataframe.transpose()
  age      city  name # After transposing, inner keys become column names
0  16  New york  Aadi
1  34    Sydney  Jack
2  30     Delhi  Riti
Posted by: Guest on August-20-2020

Code answers related to "convert dict of dict to dataframe"

Python Answers by Framework

Browse Popular Code Answers by Language