Series 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

Series in Dataframe() :


program-

import pandas

s1=pandas.Series([1,2,3,4,5])
s2=pandas.Series([1.1,2.2,3.3])
s3=pandas.Series(['a','b','c','d'])
d={'first':s1,'second':s2,'third':s3}
ans=pandas.DataFrame(d)
print(ans)


output-

first second third
0 1 1.1 a
1 2 2.2 b
2 3 3.3 c
3 4 NaN d
4 5 NaN NaN

-In this program, firstly we create a three series using pandas Series() function then make dictionary consider series 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.
-Where NaN is 'Not a number', that means if value is not their at index value then it will show NaN, that means empty value.




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!