Informatics Practices

Pandas DataFrame | Complete Notes with Examples | CBSE Class 12 Informatics Practices (2026–27)

Class 12 · Informatics Practices

Pandas DataFrame

A DataFrame is the most important data structure provided by the Pandas library. It is used to store data in a tabular form consisting of rows and columns, similar to an Excel worksheet or a database table.

Almost every data analysis task in Python uses DataFrames because they are easy to create, organize, filter, and analyze.


What is a DataFrame?

Definition

A DataFrame is a two-dimensional labeled data structure in Pandas that stores data in rows and columns. Each column can contain a different data type.


Why Do We Use DataFrames?

  • Store data in tabular form.
  • Represent real-world datasets.
  • Perform data analysis efficiently.
  • Read and write CSV or Excel files.
  • Filter, sort, and modify data easily.
  • Handle large datasets efficiently.

Characteristics of a DataFrame

Property Description
Two-Dimensional Stores data in rows and columns.
Labeled Rows and columns have labels.
Mutable Rows and columns can be added or removed.
Heterogeneous Different columns can have different data types.
Size Can store thousands or millions of records.

Structure of a DataFrame


      Name     Marks    City

0     Amit      85     Jaipur

1     Neha      91     Delhi

2     Rohan     78     Mumbai

Here,

  • Rows are identified by an Index.
  • Columns have Names (Labels).
  • Each cell stores one value.

Creating a DataFrame

Syntax


import pandas as pd

df = pd.DataFrame(data)


Creating a DataFrame from a Dictionary of Lists


import pandas as pd

data = {

"Name":["Amit","Neha","Rohan"],

"Marks":[85,92,78],

"City":["Jaipur","Delhi","Mumbai"]

}

df = pd.DataFrame(data)

print(df)

Output

    Name   Marks    City

0   Amit      85   Jaipur

1   Neha      92   Delhi

2  Rohan      78   Mumbai


Creating a DataFrame from a Dictionary of Series


import pandas as pd

name = pd.Series(["Amit","Neha","Rohan"])

marks = pd.Series([85,92,78])

city = pd.Series(["Jaipur","Delhi","Mumbai"])

data = {

"Name":name,

"Marks":marks,

"City":city

}

df = pd.DataFrame(data)

print(df)


Creating a DataFrame from a List of Dictionaries


import pandas as pd

students = [

{"Name":"Amit","Marks":85},

{"Name":"Neha","Marks":91},

{"Name":"Rohan","Marks":78}

]

df = pd.DataFrame(students)

print(df)


Creating a DataFrame from a CSV File

Suppose a file named student.csv already exists.


import pandas as pd

df = pd.read_csv("student.csv")

print(df)


Displaying a DataFrame


print(df)

The print() function displays the complete DataFrame.


Shape of a DataFrame

The shape attribute returns the number of rows and columns.


print(df.shape)

Output

(3,3)

Meaning:

  • 3 Rows
  • 3 Columns

Size of a DataFrame

Returns the total number of elements.


print(df.size)

Output

9


Index of a DataFrame


print(df.index)

Output

RangeIndex(start=0, stop=3, step=1)


Column Names


print(df.columns)

Output

Index(['Name','Marks','City'])


Data Types


print(df.dtypes)

Output

Name     object

Marks     int64

City      object

dtype: object


info() Function

Displays complete information about the DataFrame.


df.info()

It shows:

  • Number of rows
  • Number of columns
  • Column names
  • Data types
  • Memory usage
  • Non-null values

describe() Function

Displays statistical information about numerical columns.


df.describe()

It calculates:

  • Count
  • Mean
  • Standard Deviation
  • Minimum
  • Maximum
  • 25%
  • 50% (Median)
  • 75%

Difference Between Series and DataFrame

Series DataFrame
One-dimensional Two-dimensional
Single column Multiple columns
Stores one type of data Stores multiple columns of different data types
Can be a part of a DataFrame Collection of multiple Series

Real-Life Applications

Field Example
School Student Result Sheet
Hospital Patient Database
Bank Customer Records
Business Sales Report
Sports Player Statistics

Common Errors

Error Reason
ValueError Columns have unequal lengths.
FileNotFoundError CSV file does not exist.
KeyError Incorrect column name.

Quick Revision

Concept Remember
DataFrame 2-D Data Structure
Shape Rows × Columns
Size Total Elements
Columns Column Labels
Index Row Labels
info() Complete Information
describe() Statistical Summary

CBSE Exam Tips

  • Remember all four methods of creating a DataFrame.
  • Know the difference between shape and size.
  • Practice the outputs of info() and describe().
  • Remember that a DataFrame is a collection of Series.
  • Understand how CSV files are imported using read_csv().

Summary

A DataFrame is a two-dimensional labeled data structure in Pandas used for storing and analyzing tabular data. It can be created from dictionaries, Series, lists of dictionaries, and CSV files. DataFrames provide powerful features such as viewing data, checking its structure, and performing statistical analysis, making them the most widely used data structure in data science and analytics.