0% found this document useful (0 votes)
17 views4 pages

Assessment

The document discusses Python libraries and how they can be used to perform various tasks like data analysis, machine learning, and interacting with databases. It provides examples of popular Python libraries like NumPy, Pandas, Matplotlib, Scikit-learn, TensorFlow, and OpenCV and describes their main roles and uses. It also explains how to connect to and interact with a MySQL database from Python using the mysql-connector library.
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)
17 views4 pages

Assessment

The document discusses Python libraries and how they can be used to perform various tasks like data analysis, machine learning, and interacting with databases. It provides examples of popular Python libraries like NumPy, Pandas, Matplotlib, Scikit-learn, TensorFlow, and OpenCV and describes their main roles and uses. It also explains how to connect to and interact with a MySQL database from Python using the mysql-connector library.
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
You are on page 1/ 4

Department: Information and Communication Technology (ICT)

Option: Information Technology (IT)

Name of Module: Python and fundamentals of AI

Module code: ITLPA701

Level: VII

Reg_No: 21rp01138

Assessment

 What are the libraries/Modules used in python?


 What are their role?
 How are they used?

Python Libraries are a set of useful functions that eliminate the need for writing codes from scratch.
There are over 137,000 python libraries present today, and they play a vital role in developing machine
learning, data science, data visualization, image and data manipulation applications, and more. Let us
briefly introduce Python Programming Language and then directly dive into the most popular Python
libraries.

A library is a collection of pre-combined codes that can be used iteratively to reduce the time required
to code. They are particularly useful for accessing the pre-written frequently used codes instead of
writing them from scratch every single time. Similar to physical libraries, these are a collection of
reusable resources, which means every library has a root source. This is the foundation behind the
numerous open-source libraries available in Python.

Python library is a collection of modules that contain functions and classes that can be used by other
programs to perform various tasks.

Python libraries are a collection of related modules that contain bundles of codes that can be used in
different programs. Making use of Python libraries makes it convenient for the programmer as they
wouldn’t have to write the same code multiple times for different programs. Some common libraries are
OpenCV, Apache Spark, TensorFlow, NumPy, etc.
Top Python Libraries List:

1. NumPy:

Role: Numerical computing library.

Used for mathematical operations on large, multi-dimensional arrays and matrices.

2. Pandas:

Role: Data manipulation and analysis library.

Used for working with structured data, like tables or SQL tables.

3. Matplotlib:

Role: Plotting and visualization library.

Used for creating static, interactive, and animated visualizations in Python.

4. Seaborn:

Role: Statistical data visualization library.

Built on top of Matplotlib, it provides a high-level interface for drawing attractive and informative
statistical graphics.

5. Scikit-learn:

Role: Machine learning library.

Used for implementing various machine learning algorithms and tools for data mining and data analysis.

6. TensorFlow and PyTorch:

Role: Deep learning libraries.

Used for building and training neural network models.

7. Requests:

Role: HTTP library.

Used for making HTTP requests, such as fetching data from a web API.

8. Beautiful Soup:

Role: Web scraping library.

Used for pulling data out of HTML and XML files.

9. Django and Flask:

Role: Web frameworks.


Used for developing web applications.

10. OpenCV:

Role: Computer vision library.

Used for image and video processing.

 How can you interact with the database using python?

MySQL is a powerful, open-source relational database management system. It is widely used in web
development and large-scale applications. To connect to a MySQL database using Python, you must
install the mysql-connector-python library.

Step 1: Install mysql-connector-python Library

Install the library using pip:

pip install mysql-connector-python

Shell

Step 2: Import mysql.connector Library

Import the mysql.connector library in your Python script:

import mysql.connector

Python

Step 3: Create a Connection to the Database

Create a connection to the MySQL database using the connect() method. Provide the necessary
credentials like hostname, username, password, and database name:

conn = mysql.connector.connect(

host="localhost",

user="your_username",

password="your_password",

database="your_database"

Python

Step 4: Create a Cursor Object

Create a cursor object to execute SQL commands on the database:

cursor = conn.cursor()

Python
Step 5: Execute SQL Commands

Now you can execute SQL commands using the execute() method on the cursor object:

cursor.execute("CREATE TABLE IF NOT EXISTS users (id INT AUTO_INCREMENT PRIMARY KEY, name
VARCHAR(255), age INT)")

Python

Step 6: Commit Changes and Close the Connection

After executing SQL commands, you need to commit changes to the database using the commit()
method. Finally, close the connection using the close() method:

conn.commit()

conn.close()

 References

1. Reintech. (n.d.). Connect to a Database with Python. Reintech. https://reintech.io/blog/connect-


to-database-with-python

2. W3Schools. (n.d.). Python MySQL Get Started. W3Schools.


https://www.w3schools.com/python/python_mysql_getstarted.asp

3. MyGreatLearning. (n.d.). Top 9 Open Source Python Libraries You Must Try in 2021.
MyGreatLearning. https://www.mygreatlearning.com/blog/open-source-python-libraries

4. Real Python. (n.d.). Python SQL Libraries: The Ultimate List. Real Python.
https://realpython.com/python-sql-libraries/

You might also like