DATAFRAME
DATAFRAME
• It is a two-dimensional object that is useful in representing data in the form of
rows and columns. It is similar to a spreadsheet or an SQL table.
• This is the most commonly used pandas object. Once we store the data into the
Dataframe, we can perform various operations that are useful in analyzing and
understanding the data.
PROPERTIES OF DATAFRAME
1. A Dataframe has axes (indices)-
➢ Row index (axis=0)
➢ Column index (axes=1)
2. It is similar to a spreadsheet , whose row index is called index and
column index is called column name.
3. A Dataframe contains Heterogeneous data.
4. A Dataframe Size is Mutable.
5. A Dataframe Data is Mutable.
A data frame can be created using any of the following
1. Series
2. Lists
3. Dictionary
4. A numpy 2D array
Create an empty DataFrame
Output
How to create Dataframe From Series
Program Output-
Default col
name as 0
import pandas as pd 0
s = [Link]([“Acc”, “BST”, “IP”, “Eco”]) 0 Acc
df=[Link](s) 1 BST
print(df) 2 IP
3 Eco
Default row index
How to create Dataframe From Series
with user defined index/label.
Program Output-
Default col
name as 0
import pandas as pd 0
Sub1 Acc
s = [Link]([“Acc”, “BST”, “IP”, “Eco”], Sub2 BST
index=[“Sub1”, “Sub2” , “Sub3”, “Sub4”] ) Sub3 IP
Sub4 Eco
df=[Link](s)
print(df) user defines row
label
Class Assessment
Q1. DataFrame size is :-
a) Mutable
b) Immutable
Q2. DataFrame is a ………..dimensional data structure and contains
…………… data .
a) 1 , Homogeneous
b) 2 , Homogeneous
c) 1 , Heterogeneous
d) 2 , Heterogeneous
Q3. Which Package is used to import DataFrame and Series function?
c) Numpy
d) Pandas
Home work
• Create a dataframe of your subject marks using Series.
• Create a dataframe of employees with emp_id as index and salary as
data using Series.