DataFrame (Class 12 Python
Pandas)
– A DataFrame is a 2D labeled data structure.
– It consists of rows and columns.
– Part of the Pandas library.
Features of DataFrame
– Two dimensional
‑
– Heterogeneous data
– Mutable
– Labeled rows and columns
Creating DataFrame – From List
– Using: pd.DataFrame(list)
– Example included in later slides
Creating DataFrame – From
Dictionary of Lists
– Each key becomes a column
– Each value is a list of column entries
Creating DataFrame – From
Dictionary of Series
– Series objects combine into a DataFrame
Creating DataFrame – From List of
Dictionaries
– Each dictionary becomes a row
Attributes of DataFrame
– shape
– size
– values
– columns
– index
Attribute: shape
– Returns number of rows and columns
Attribute: size
– Returns total number of elements
Attribute: columns
– Gives list of column labels
Attribute: index
– Gives row labels
Accessing Data in DataFrame
– Column access: df['col']
– Row access: loc & iloc
loc[]
– Label-based data selection
iloc[]
– Index-based data selection
Adding Columns
– Direct assignment: df['new']=value
Deleting Columns
– Using del df['col']
– or df.drop()
Adding Rows
– Using loc
– or append (deprecated)
Deleting Rows
– Using df.drop(index)
Operations on DataFrame
– head(), tail()
– describe()
– sum()
– mean()
Example Code
– import pandas as pd
– data={'Name':['A','B'], 'Marks':[90,85]}
– df=pd.DataFrame(data)
– print(df)
Real Life Use
– Used in data analysis
– Machine learning
– Handling tabular data
End
– Thank you!

MOsTIMPCBSETOPDataFrame_Class12_PPT.pptx