dictionary to dataframe code example
Example 1: pandas dataframe from dict
data = {'col_1': [3, 2, 1, 0], 'col_2': ['a', 'b', 'c', 'd']}
pd.DataFrame.from_dict(data)
Example 2: how to make a pandas dataframe from a dictionary
>>> data = {'col_1': [3, 2, 1, 0], 'col_2': ['a', 'b', 'c', 'd']}
>>> pd.DataFrame.from_dict(data)
Example 3: convert a dictionary into dataframe python
import pandas as pd
data = {'col_1': [3, 2, 1, 0], 'col_2': ['a', 'b', 'c', 'd']}
pd.DataFrame.from_dict(data, orient='index').T
Example 4: convert dict to dataframe
pd.DataFrame.from_dict(data, orient='index').T
Example 5: python How to convert a dictionary of dictionaries nested dictionary to a Pandas dataframe
dataframe = pd.DataFrame(nested_dictionary)
dataframe = dataframe.transpose()
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'
}
}
pandas_dataframe = pd.DataFrame(student_data)
print(pandas_dataframe)
0 1 2
age 16 34 30
city New york Sydney Delhi
name Aadi Jack Riti
pandas_dataframe.transpose()
age city name
0 16 New york Aadi
1 34 Sydney Jack
2 30 Delhi Riti
Example 6: dataframe from dict
pd.DataFrame.from_dict(data)