






Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!







This guide covers five essential Python libraries every MCA student must master: SQLite for databases, NumPy for numerical computing, Pandas for data analysis, Matplotlib for visualization, and Scikit-learn for machine learning. Each section breaks down concepts in plain English with real code examples you can run and experiment with. Whether you're preparing for exams or building real projects, this guide gives you a clear, practical foundation in Python's data ecosystem.
PART A โ DATABASES
A database is an organized collection of related data that can be easily stored, retrieved, updated, and managed. Think of it as a digital filing cabinet where information is structured so you can find exactly what you need, fast. Common examples include a Student Database , Employee Database , and Library Database.
Python can interact with many databases โ SQLite , MySQL, PostgreSQL, and Oracle. For MCA exams, SQLite is the most commonly used because it is built directly into Python โ no installation needed.
To get started, import the sqlite3 module and connect to a database file:
import sqlite
conn = sqlite3.connect("college.db") print("Database Connected")
The sqlite3.connect() function creates a new database file if it doesn't exist, or opens it if it does. The connection object conn is your gateway to the database.
The Cursor Object
Once connected, you need a cursor to execute SQL queries. Think of the cursor as a messenger โ it carries your commands to the database and brings back results. You create a cursor using conn.cursor().
cursor = conn.cursor()
With the cursor ready, you can run any SQL command โ creating tables, inserting data, reading records, updating values, or deleting rows. After executing write operations (INSERT, UPDATE, DELETE), always call conn.commit() to save changes, and conn.close() when done to release the connection.
PART A โ DATABASES
CRUD stands for Create, Read, Update, Delete โ the four fundamental operations you perform on data in any database. In SQL, these map to INSERT, SELECT, UPDATE, and DELETE. Together with DDL, these form the complete toolkit for working with databases in Python.
cursor.execute( "INSERT INTO Student VALUES( 1 ,'Rahul', 85 )" ) conn.commit()
Inserts a new row into the Student table.
cursor.execute("SELECT * FROM Student") rows = cursor.fetchall() for row in rows: print(row)
Output: (1, 'Rahul', 85)
cursor.execute( "UPDATE Student SET marks= 95 WHERE id= 1 " ) conn.commit()
Changes Rahul's marks from 85 to 95.
cursor.execute( "DELETE FROM Student WHERE id= 1 " ) conn.commit()
Removes the student with id=1.
DDL vs DML โ Key Difference
DDL (Data Definition Language) defines the database structure โ commands like CREATE, ALTER, DROP, and TRUNCATE change the schema. DML (Data Manipulation Language) works with the data inside tables โ commands like INSERT, UPDATE, DELETE, and SELECT change records. Remember: DDL changes the container, DML changes the contents.
Defines database structure Manipulates data inside tables
CREATE, ALTER, DROP, TRUNCATE INSERT, UPDATE, DELETE, SELECT
Changes schema Changes records
PART B โ NUMPY
NumPy (Numerical Python) is one of the most important libraries in the Python data ecosystem. It is designed for numerical computing , scientific calculations, matrix operations, and fast array processing. NumPy arrays are significantly faster than regular Python lists , use less memory , and support vectorized operations โ meaning you can apply math to entire arrays without writing loops.
NumPy arrays are optimized for speed and can process millions of numbers much faster than standard Python lists.
NumPy stores data more efficiently, using significantly less memory compared to equivalent Python list structures.
Apply mathematical operations to entire arrays at once without writing explicit for-loops โ cleaner and faster code.
Creating Arrays
Import NumPy with the alias np (a universal convention). Use np.array() to create arrays. You can create 1D arrays (a single row of values) or 2D arrays (rows and columns, like a table).
import numpy as np
a = np.array([ 1 , 2 , 3 , 4 ]) print(a)
a = np.array([[1, 2], [3, 4]]) print(a)
PART C โ PANDAS
Pandas is the go-to Python library for data analysis, data cleaning, and data manipulation. It is built on top of NumPy and provides easy-to-use data structures that resemble spreadsheets or SQL tables. Import it with the alias pd โ a universal convention in the Python community.
1
A Series is a one-dimensional labeled array, like a single column in a spreadsheet. Each value has an index label (0, 1, 2โฆ by default).
import pandas as pd s = pd.Series([ 10 , 20 , 30 ]) print(s)
2
A DataFrame is a two- dimensional table โ rows and columns, just like an Excel sheet. You can create one from a Python dictionary.
data = { "Name": ["A", "B"], "Marks": [90, 85] } df = pd.DataFrame(data) print(df)
3
A Panel was a three-dimensional data structure in older Pandas versions. It has been removed from modern Pandas , but some MCA syllabi still include it. Conceptually: Series โ 1D, DataFrame โ 2D, Panel โ 3D.
PART C โ PANDAS
Beyond creating DataFrames, Pandas gives you powerful tools to explore, reorganize, and navigate your data. You can change row labels with reindexing , sort data by any column, loop through rows, and inspect the index structure. These operations are essential for real-world data analysis tasks.
The index is the label system that identifies each row in a DataFrame. You can view it with df.index and change it with reindex().
df.index
df = df.reindex([1, 0])
Reindexing is useful when you need to reorder rows or align two DataFrames by their labels.
Sort a DataFrame by any column using sort_values(). To loop through every row, use iterrows().
df.sort_values("Marks")
for i, row in df.iterrows(): print(row)
iterrows() returns both the index (i) and the row data, making it easy to process each row one at a time.
Single labeled column of data
Full table with rows and columns
Deprecated 3D structure (legacy)
PART E โ SCIKIT-LEARN
Scikit-learn (imported as sklearn) is Python's most widely used library for machine learning. It provides simple, efficient tools for classification, regression, clustering, and prediction. The workflow follows a clear pattern: load data โ train a model โ make predictions โ save the model.
This four-step pattern is the foundation of almost every machine learning project in Scikit-learn. Once you understand it, you can swap in different datasets and models easily.
from sklearn.datasets import load_iris from sklearn.tree import DecisionTreeClassifier
data = load_iris() model = DecisionTreeClassifier() model.fit(data.data, data.target)
load_iris() provides a built-in dataset. fit() trains the model on the data. The decision tree learns patterns to classify iris flowers.
prediction = model.predict( [[5.1, 3.5, 1.4, 0.2]] ) print(prediction)
import joblib joblib.dump(model, "model.pkl")
model = joblib.load("model.pkl")
Model persistence means saving a trained model so you don't have to retrain it every time. joblib.dump() saves it; joblib.load() restores it โ ready to predict immediately.
Quick Recap: You've now covered all five pillars โ SQLite (databases & CRUD), NumPy (arrays & math), Pandas (Series & DataFrames), Matplotlib (charts & graphs), and Scikit-learn (ML training & prediction). Master these and you have a complete Python data toolkit for exams and beyond.