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: