Hello guys. How are you all? I hope you all fine. In this tutorial we will learn about how to convert Python Dictionary to Pandas DataFrame. so without wasting time lets learn about of this.
How to convert Python Dictionary to Pandas DataFrame
convert Python Dictionary to Pandas DataFrame
to convert Python Dictionary to Pandas DataFrame just use pandas.dataframe().from_dict() By using pandas.dataframe().from_dict() you can convert Python Dictionary to Pandas DataFrame. Lets learn about of this by given below example:
import pandas as pd print(pd.DataFrame.from_dict({ 'heeya': 43, 'meet': 45, 'jaydeep': 47, 'romil': 41, 'vrunda': 48, 'nirali': 43}, orient='index').rename(columns={0:'marks'}))
Output :marks heeya 43 meet 45 jaydeep 47 romil 41 vrunda 48 nirali 43
How to convert Python Dictionary to Pandas DataFrame
to convert Python Dictionary to Pandas DataFrame just Use pd.dataframe().By using pd.dataframe() you can convert Python Dictionary to Pandas DataFrame. Lets learn about of this by given below example:
import pandas as pd marks_dict = { 'heeya': 43, 'meet': 45, 'jaydeep': 47, 'romil': 41, 'vrunda': 48, 'nirali': 43} print(pd.DataFrame(list(marks_dict.items()), columns=['student', 'marks']))
Output :student marks 0 heeya 43 1 meet 45 2 jaydeep 47 3 romil 41 4 vrunda 48 5 nirali 43
dictionary to dataframe
To convert Python Dictionary to Pandas DataFrame just use pandas.dataframe().from_dict() By using pandas.dataframe().from_dict() you can convert Python Dictionary to Pandas DataFrame. Lets learn about of this by given below example:
import pandas as pd print(pd.DataFrame.from_dict({ 'heeya': 43, 'meet': 45, 'jaydeep': 47, 'romil': 41, 'vrunda': 48, 'nirali': 43}, orient='index').rename(columns={0:'marks'}))
Output :marks heeya 43 meet 45 jaydeep 47 romil 41 vrunda 48 nirali 43
Method 1: Use pandas.dataframe().from_dict()
Just Use pandas.dataframe().from_dict(). Lets learn about of this by given below example:
import pandas as pd
print(pd.DataFrame.from_dict({
'heeya': 43,
'meet': 45,
'jaydeep': 47,
'romil': 41,
'vrunda': 48,
'nirali': 43}, orient='index').rename(columns={0:'marks'}))
Output :
marks
heeya 43
meet 45
jaydeep 47
romil 41
vrunda 48
nirali 43
Method 2: Use pd.dataframe()
By using pd.dataframe() you can convert Dictionary to Pandas DataFrame. Lets learn about of this by given below example:
import pandas as pd
marks_dict = {
'heeya': 43,
'meet': 45,
'jaydeep': 47,
'romil': 41,
'vrunda': 48,
'nirali': 43}
print(pd.DataFrame(list(marks_dict.items()),
columns=['student', 'marks']))
Output :
student marks
0 heeya 43
1 meet 45
2 jaydeep 47
3 romil 41
4 vrunda 48
5 nirali 43
Conclusion
It’s all About this Tutorial. Hope all methods helped you a lot. Comment below Your thoughts and your queries. Also, Comment below which method worked for you?
Also, Read