0% found this document useful (0 votes)
3 views9 pages

Python Libraries, Packages, and APIs Guide

The document outlines several programming experiments focused on utilizing libraries and packages in Python, including NumPy and Pandas for data manipulation and visualization. It covers creating Python packages, working with virtual environments, extracting data from APIs, and performing CRUD operations with SQLite databases. Each section includes objectives, tasks, and source code examples to illustrate the concepts discussed.

Uploaded by

248t1a0310
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views9 pages

Python Libraries, Packages, and APIs Guide

The document outlines several programming experiments focused on utilizing libraries and packages in Python, including NumPy and Pandas for data manipulation and visualization. It covers creating Python packages, working with virtual environments, extracting data from APIs, and performing CRUD operations with SQLite databases. Each section includes objectives, tasks, and source code examples to illustrate the concepts discussed.

Uploaded by

248t1a0310
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Experiment 9:Libraries and Packages

- Objective: Utilize third-party libraries and create Python


packages.
Tasks:
9a - Install and use libraries like NumPy and Pandas.
STEP :1
!pip install pandas

STEP :2
import pandas as pd
print(pd.__version__)
2.1.4
9b- Create a simple Python package and distribute it.
import numpy as np
import pandas as pd
a = [Link]([1, 2, 3])
print("Numpy Array:", a)
df = [Link]({"A":[1,2,3],"B":[4,5,6]})
print(df)
output:
9c- Work with virtual environments to manage dependencies.
I will explain on Friday’s lab
Program --10: Working with Data
-Objective: Perform data manipulation and visualization.
Tasks: - Use Pandas to load, manipulate, and analyze datasets.
- Create visualizations using Matplotlib and Seaborn.
- Conduct basic data analysis tasks and summarize findings.
SOURCE CODE :
import pandas as pd
import [Link] as plt
data = {"Name":["A","B","C"],"Marks":[85,90,78]}
df = [Link](data)
print(df)
[Link](kind="bar", x="Name", y="Marks")
[Link]()

OUTPUT :
Program --11- Objective: Extract data from the web and interact
with APIs.
Tasks: - Access and parse data from RESTful APIs.
- Process and analyze JSON data from APIs.
PROGRAM:
import requests
● \\ the requests library, which is a popular third-party
Python module for sending HTTP requests
(like GET, POST, PUT, DELETE, etc.).
response = [Link]("[Link]
● \\ Allows your program to communicate with web
servers and APIs (like GitHub’s API in this
example).
● This line sends an HTTP GET request to the URL:
[Link]
● The GitHub API responds with some JSON data
describing the API itself.
● The [Link]() function returns a Response object,
which contains all the details of the server’s
reply (like status code, headers, and body).
print("Status:", response.status_code)
● \\ This line prints the HTTP status code returned by
the server.
● response.status_code might be:
● 200 OK (successful request)
● 404 Not Found
● 500 Internal Server Error, etc.
print([Link]())
● \\ The .json() method tries to parse the response body
as JSON and return it as a Python object (usually
a dictionary or list).
● Since the GitHub API responds with JSON, this
converts that response into something readable
by Python.
OUTPUT:

Program 12: Databases –


Objective:Work with databases in Python.
Tasks:
- Connect to a database using SQLite and SQLAlchemy.
- Perform CRUD operations on the database.
- Write queries to manage and retrieve data
SOURCE CODE :
import sqlite3
● \\ Imports Python’s built-in SQLite3 library.
● SQLite is a lightweight database engine that stores
data in a local file (no need for a server).
● You use this module to create, query, and manage
SQLite databases.

conn = [Link]("[Link]")
● \\ Creates a connection object named conn to a
database file called [Link].
● If the file doesn’t exist, SQLite automatically creates it
in the current directory.
● The connection allows Python to communicate with
the database.
cursor = [Link]()
● \\ Creates a cursor object named cursor.
● The cursor is used to execute SQL commands (like
CREATE, INSERT, SELECT, etc.)
and fetch results.
● Think of it as a “pointer” or “controller” for database
operations.
[Link]("CREATE TABLE IF NOT EXISTS student(name
TEXT, age INT)")
● \\ Executes an SQL command that creates a table
named student.
● The table has two columns:
● name stores text (string) values.
● age stores integer (number) values.
● The phrase IF NOT EXISTS ensures that the table is
only created once — it won’t
cause an error if the table
already exists.
[Link]("INSERT INTO student VALUES('Gowthami', 20)")
● \\ Inserts a new record (row) into the student table.
● The values inserted are:
● 'Gowthami' for the name column
● 20 for the age column

[Link]()
● \\ Saves (commits) any changes made to the
database.
for row in [Link]("SELECT * FROM student"):
print(row)
[Link]()

OUTPUT :
('Gowthami', 20)

You might also like