Dictionary in Pandas DataFrame in Python by R4R Team

DataFrames:
-It is a two dimensional data structure defined in pandas which consists of rows and columns.

Syntax-

pandas.DataFrame(data)

Here data can be :
1. one or more dictionary.
2. one or more series
3. 2D numpy Ndarray

Dictionary in DataFrame() :


program-

import pandas

d={1:'a',2:'b',3:'c',4:'d'}
ans=pandas.DataFrame(d,index=[0,1,2,3])
print(ans)


output-

1 2 3 4
0 a b c d
1 a b c d
2 a b c d
3 a b c d


Pass two dictionary in DataFrame():

program-

import pandas

d={1:'a',2:'b'}
d={'first':d,'second':d}

ans=pandas.DataFrame(d)
print(ans)


output-


first second
1 a a
2 b b




Leave a Comment:
Search
R4R Team
R4Rin Top Tutorials are Core Java,Hibernate ,Spring,Sturts.The content on R4R.in website is done by expert team not only with the help of books but along with the strong professional knowledge in all context like coding,designing, marketing,etc!