Python-U-5-ONE-SHOT-Notes
Python-U-5-ONE-SHOT-Notes
Tech III-Sem
Python
Crash Course
Unit-5 in One Shot Pragya Ma'am
IMPORTANT QUESTION OF UNIT 5
1. What is numpy , pandas, matplotlib
2. Explain different types of plot(line, bar, scatter plot with example)
3. Write a program transpose a matrix( see numpy program)
4. Write a program to add /sub two matrices (see numpy program
5. Write a program to perform matrix multiplication(see numpy program)
6 Write a program to reverse an array
7 Explain panda data series and explain its operation
8. What is panda dataframe. Write a program to create dataframe from dictionary
10. What is python? How python is interpreted? What are the toolsthat help to find bugs or perform static
analysis? What are python decorators?
1
IMPORTANT QUESTION OF UNIT 5
11. Describe how to generate random number using numpy. writea python m program to create an array of 5
random number integer between 10 and 50
12. What is trinket? Explain some of its widget with example
2
SYLLABUS OF UNIT 5
Python packages: Simple programs using the built-in functions of packages matplotlib, numpy,
pandas etc. GUI Programming: Tkinter introduction, Tkinter and PythonProgramming, Tk Widgets,
Tkinter examples. Python programming with IDE.
1
AKTU B.Tech Second Year
PYTHON PROGRAMMING
Unit 5
Python packages
LEC-1
Today’s Target
NUMPY
AKTU PYQs
By
Pragya Rajvanshi
1
Numpy
NumPy is an open-source Python
library that provides support for
large, multi-dimensional arrays
and matrices.
It also have a collection of high-
level mathematical functions to
operate on arrays.
2
NumPy Basic Operations
1. Operations on a single NumPy array
3
4
NumPy – Unary Operators
Many unary operations are provided as a method of ndarray class. This includes sum, min, max,
etc. These functions can also be applied row-wise or column-wise by setting an axis parameter
5
NumPy – Binary Operators
These operations apply to the array elementwise and a new array is created. You can use all basic arithmetic operators
like +, -, /, etc. In the case of +=, -=, = operators, the existing array is modified
6
Numpy sorting array
7
Write a NumPy program to convert a list of numeric values into a one-dimensional NumPy
array.
8
Write a NumPy program to create a 3x3 matrix with values ranging from 2 to 10.
9
Write a NumPy program to reverse an array (the first element becomes the last)
10
11
Write a NumPy program to find common values between two arrays.
12
Write a NumPy program to get the unique elements of an array.
13
Write a NumPy program to find the set difference between two arrays. The set difference will
return sorted, distinct values in array1 that are not in array2
14
Union of two array
15
AKTU B.Tech Second Year
PYTHON PROGRAMMING
Unit 5
LEC-2
Python packages
Today’s Target
NUMPY program
AKTU PYQs
By
Pragya Rajvanshi
1
Write a python program to create an array of 5 random integer between 10 and 50(inclusive 10
and 50)
2
Write a NumPy program to shuffle numbers between 0 and 10 (inclusive).
3
Write a NumPy program to create a 3x3x3 array with random values
4
Panda Panda data series
Pandas is a powerful and open- Pandas Series is a one-dimensional labeled array
source Python library. The Pandas capable of holding data of any type (integer, string,
library is used for data manipulation float, python objects, etc.).
and analysis.
Pandas is well-suited for working
with tabular data, such as
spreadsheet.
Data Structures in Pandas Library
series and frames The axis labels are collectively called index. Pandas
Series is nothing but a column in an excel sheet.
5
Creating series from list Accessing Element from Series with Position
6
Accessing Element Using Label (index)
7
Binary operator
8
Pandas DataFrame
Pandas DataFrame is two-dimensional size-mutable, potentially heterogeneous tabular data
structure with labeled axes (rows and columns). A Data frame is a two-dimensional data structure,
i.e., data is aligned in a tabular fashion in rows and columns. Pandas DataFrame consists of three
principal components, the data, rows, and columns.
9
Create a Pandas DataFrame from dictionary
10
Create a Pandas DataFrame from dictionary
11
Write a Pandas program to compare the elements of the two Pandas Series. Sample Series: [2, 4, 6,
8, 10], [1, 3, 5, 7, 10]
12
Write a Pandas program to sort a given Series.
13
AKTU B.Tech Second Year
PYTHON PROGRAMMING
Unit 5
Python file operations
LEC-3
Today’s Target
PYTHON WITH IDE
AKTU PYQs
By
Pragya Rajvanshi
1
Syllabus
Python packages: Simple programs using the built-in functions of packages matplotlib,
numpy, pandas etc. GUI Programming: Tkinter introduction, Tkinter and
PythonProgramming, Tk Widgets, Tkinter examples. Python programming with IDE.
2
Python Features:
Python is a high-level,
Easy to Learn and Use: Simple syntax like plain English.
interpreted programming
Cross-Platform: Works on Windows, macOS, Linux, etc.
language known for its
Large Library: Ready-to-use tools for tasks like math, web, and
simplicity and readability
data.
You can use it to create
Dynamic Typing: No need to define variable types explicitly.
websites, analyze data,
Community Support: Lots of resources and help available
automate tasks, or build apps.
online.
It’s beginner-friendly and lets
you write code that’s easy to
read and understand.
3
How python is interpreted? The interpreter reads the code line by line.
Python is interpreted because its code is 3.Bytecode Conversion:
executed line by line by the Python interpreter. The interpreter translates your source code
Here's how it works: into an intermediate form called bytecode.
1.Source Code: Bytecode is a simplified version of your code
You write Python code in a file (e.g., that is easier for the computer to understand.
example.py). This bytecode is stored temporarily in memory
This is the human-readable version of your or as a .pyc file (if caching is enabled).
program. .
2.Python Interpreter:
When you run the code (e.g., using python
example.py), the Python interpreter starts
working. 4
4.Python Virtual Machine (PVM): Static analysis
The bytecode is executed by the Python It is the process of analyzing code without executing
Virtual Machine. it. It checks for bugs, errors, security vulnerabilities,
The PVM takes each instruction from and code quality issues by examining the source code
the bytecode and executes it on your or bytecode.
computer. Key Points:
5.Output: How it works: Tools analyze the code structure,
The interpreter runs the code step by syntax, and logic to detect potential problems.
step, producing results as it goes. Purpose: To catch errors early in the development
If there’s an error in your code, Python process before the code is run or tested.
stops and shows an error message. Examples: Finding unused variables, type
mismatches, or missing imports.
5
Tools that help to find bugs or Features of PyLint:
perform static analysis 1.Code Quality Checks:
PyLint is a popular Python Detects issues like unused variables, undefined variables,
tool for analyzing code to and unreachable code.
ensure it adheres to coding Ensures your code follows the Python style guide (PEP 8).
standards, finds errors, and 2.Coding Standards:
improves code quality. Highlights deviations from best practices.
It performs static code Enforces consistent naming conventions for variables,
analysis and provides classes, and methods.
suggestions for 3. Error Detection:
improvement. Finds common errors like missing imports, syntax issues, or
potential bugs.
6
Code Refactoring: PyChecker
Provides suggestions to It is a static analysis tool for Python that helps find bugs, errors,
refactor and simplify and inconsistencies in code.
code to make it cleaner It was one of the earlier tools for Python linting, though it is
and more readable. less commonly used today compared to tools like PyLint.
Custom Rules: Features:
Allows users to define 1.Bug Detection:
custom rules for Identifies syntax errors and logical mistakes in code.
analysis or disable Flags unused variables, modules, or imports.
specific checks as
2.Error Analysis:
needed.
Detects type mismatches and missing function arguments.
Highlights potential runtime errors.
7
3. Code Warnings: Python decorators
Issues warnings for
A decorator is a special type of function in Python that allows
deprecated Python features
you to modify or enhance the behavior of other functions or
or bad practices.
methods without changing their code.
4.Cross-Version Compatibility:
Decorators are often used to add functionality like logging,
Checks for compatibility
timing, or access control to functions.
issues across different
Python versions.
8
9
What is IDE? 1.Code Editor: A text editor with features like syntax highlighting,
An IDE (Integrated autocomplete, and code formatting.
Development Environment) 2.Debugger:Helps identify and fix errors in your code by running it
is a software application step by step.
that provides tools to help 3.Compiler/Interpreter: Converts your source code into
programmers write, debug, executable code (or interprets it for languages like Python).
and manage code efficiently. 4.Project Management: Allows you to organize files and folders
It integrates several features within a project.
into one interface, making 5.Integrated Tools: Includes tools for version control (e.g., Git),
the development process testing, and deployment.
easier and faster. .
10
SOME OF IDE Key features :
1. PyCharm 1.Code Editor:
It is a popular Integrated Smart code completion and suggestions.
Development Environment Syntax highlighting and formatting.
(IDE) specifically designed 2.Debugger:
for Python development. Powerful tools to identify and fix errors in Python code.
It is developed by JetBrains 3.Code Analysis:
and provides many features Highlights coding issues and suggests improvements.
to help developers write, 4.Project Management:
debug, and manage Python Helps organize files and dependencies in large projects.
projects efficiently. 5.Support for Web Development:
Includes frameworks like Django and Flask.
11
6.Testing Tools: 2. VS Code
Includes support for VS Code (Visual Studio Code) is a lightweight, powerful, and
running unit tests directly free code editor developed by Microsoft.
from the IDE. It is widely used for writing, debugging, and managing code
in multiple programming languages, including Python,
Why Use PyCharm?
JavaScript, C++ etc.
Simplifies Python
Why Use VS Code?
development with smart tools.
Free: Fully free and open-source.
Boosts productivity with
Lightweight: Ideal for both small scripts and large projects.
features like code analysis and
Customizable: Extensions let you tailor it to your needs.
debugging.
Community: Huge user base with plenty of tutorials and
Ideal for both beginners and
resources.
experienced developers.
12
Key Features of VS Code: 3.Debugger:
1.Lightweight and Fast:
Debug code with breakpoints, variable inspection, and call
Designed to be minimalistic
stack analysis.
and run efficiently on most
4.Cross-Platform:
systems.
2.Code Editor:
Available for Windows, macOS, and Linux.
16
17
What is PEP 8? Why Follow PEP 8?
PEP 8 (Python Readability: Makes code easier to read and understand.
Enhancement Proposal Consistency: Helps teams maintain a uniform coding style.
8) is the official style Best Practices: Encourages efficient code.
guide for Python code.
Key Guidelines of PEP 8:
It provides guidelines
1.Indentation:
and best practices to
Use 4 spaces per indentation level.
help developers write
2. Line length
clean, readable, and
consistent Python code.
PEP 8 recommends limiting each line of code to a maximum of 79
characters and comments or docstrings to 72 characters.
18
Spaces Comments
Use spaces around Write meaningful comments to explain why something is done.
operators and after Use # and keep comments short and clear python.
commas. Functions
Don’t add spaces inside Keep your functions small and focused on one
parentheses or Name them clearly to show what they do.
brackets.
Imports
Put imports at the top
of the file.
Import one library per
line.
19
AKTU QUESTIONS
Q.1 What is python? How python is interpreted? What are the tools AKTU 2019-20
that help to find bugs or perform static analysis? What are AKTU 2020-21
python decorators? AKTU 2022-23
Q.2 Describe how to generate random number using numpy. write AKTU 2023-24
20
AKTU B.Tech Second Year
PYTHON PROGRAMMING
Unit 5
Python file operations
LEC-4
Today’s Target
matplotlib
AKTU PYQs
By
Pragya Rajvanshi
1
Matplotlib
Visualizing data helps us understand and share information more effectively.
In Python , Matplotlib is one of the best tools for creating visualizations.
Different types of plolt
1.Line plot
2.Bar plot
3.Pie chart
4.Scatter plot
5.Histogram
2
Bar plot
A bar plot or bar chart is a graph that represents the category of data with rectangular bars with
lengths and heights that is proportional to the values which they represent.
3
Bar plot
Customizing Bar Colors
4
Bar plot
Adjusting Bar Width
5
piechart
6
7
Matplotlib Scatter
8
Scatter Plot with Multiple Datasets
9
Different Types of Plots
1. Line chart
10
Different Types of Plots
1. Line chart
11
Different Types of Plots
Multiple Plots on the Same Axis
12
Histogram
13
AKTU B.Tech Second Year
PYTHON PROGRAMMING
Unit 5
Python file operations
LEC-5
Today’s Target
Tkinter
module
By
Pragya Rajvanshi
1
Tkinter
Python Tkinter is a standard GUI (Graphical User Interface) library for Python which provides a
fast and easy way to create desktop applications.
Tkinter provides a variety of widgets like buttons, labels, text boxes, menus and more that can
be used to create interactive user interfaces.
2
Tkinter Widget
1. Label
3
Tkinter Widget
4
Tkinter Widget
1. Button
a Button is a widget that users can click to perform an action, such as closing a window, running a function, or opening
another window
5
Tkinter Widget
6
3.Entry
The Entry widget in Tkinter is used to create a single-line text input field where users can
type and edit text. It's commonly used in forms or dialogs to capture user input.
Entry(master, options)
7
Checkbutton
8
Radiobutton
9
What is python module? How to create and
import a module in python?
A module in Python is a file containing Python
functions, classes, or variables that can be
used in other programs. It helps in organizing
and reusing code. A module typically has a .py
extension.
How to Create a Python Module?
10
Different ways to import module 3.Import everything(*)
1. Import specific functions/variables
11
Significance of module in python 4.Built-in Modules
1. Code Reusability Python provides many useful built-in modules like
Instead of rewriting the same code, you math
can import and use existing modules
2. Better Code Organization
Helps divide large programs into smaller,
manageable files.
3. Avoiding Code Duplication
Saves time by defining functions once and
reusing them across different projects.
12
1. Import library from library import *
Imports the entire module but requires
Imports everything from the module directly into
module name when accessing functions or
the current namespace (no need to use the
variables.
module name).
13
Built in function matplotlib
Plot(): used to create line plots.
Bar(): used to create bar chart.
Pie(): used to create pie chart.
hist(): used to create histogram.
Scatter(): use to create scatter plot
Title(): add title to the plot.
Legend(): add a legend.
xlabels() and ylabels(): add label to the axis.
14