Ndarray 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

Ndarray in Dataframe() :


program-

import pandas

l1=[[1,2,3],[4,5,6]]
l2=[['a','b','c'],['d','e','f']]
d={'first':l1,'second':l2}
ans=pandas.DataFrame(d)
print(ans)


output-

first second
0 [1, 2, 3] [a, b, c]
1 [4, 5, 6] [d, e, f]

-In this program,we have a two Ndarray then make dictionary consider Ndarray as value in dictionary and add key by yourself then pass in DataFrame() function then it will shown the above output which is two dimension array.




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!