- List of Experiments
- Week 1
- Week 2
- Week 3
- Week 4
- Week 5
- Week 6
- Week 7
- Week 8
Exploring Python Libraries - NumPy, Plotly, Scipy
Aim: Import numpy, Plotpy and Scipy and explore their functionalities.
Import in Python
Import in Python is similar to #include header_file
in C/C++. Python modules can access code from another module by importing the file/function using the import
statement. The import statement is the most common way of invoking the import machinery, but it is not the only way.
Basic Syntax:
1 import module_name
When the import is used, it searches for the module initially in the local scope by calling the
__import__()
function. The value returned by the function is then reflected in the output of the initial code.
Example:
import math
pie = math.pi
print("The value of pi is:", pie)
Many popular Python toolboxes/libraries include:
- NumPy
- SciPy
- Pandas
- SciKit-Learn
- Visualization Libraries
- matplotlib
- Seaborn
NumPy
- Introduces objects for multidimensional arrays and matrices, as well as functions that allow for easy advanced mathematical and statistical operations on those objects.
- Provides vectorization of mathematical operations on arrays and matrices, significantly improving performance.
- Many other Python libraries are built on NumPy.
Link: NumPy
SciPy
- A collection of algorithms for linear algebra, differential equations, numerical integration, optimization, statistics, and more.
- Part of the SciPy Stack.
- Built on NumPy.
Link: SciPy
Pandas
- Adds data structures and tools designed to work with table-like data (similar to Series and Data Frames in R).
- Provides tools for data manipulation: reshaping, merging, sorting, slicing, aggregation, etc.
- Allows handling of missing data.
Link: Pandas
SciKit-Learn
- Provides machine learning algorithms: classification, regression, clustering, model validation, etc.
- Built on NumPy, SciPy, and matplotlib.
Link: SciKit-Learn
Matplotlib
- A Python 2D plotting library that produces publication-quality figures in a variety of hardcopy formats.
- A set of functionalities similar to those of MATLAB.
- Supports line plots, scatter plots, bar charts, histograms, pie charts, etc.
- Relatively low-level; some effort is needed to create advanced visualizations.
Link: Matplotlib
Sample Viva Questions and Answers
What is NumPy, and what are its primary functionalities?
NumPy is a fundamental library for numerical computing in Python, providing support for arrays, matrices, and a wide range of mathematical functions.How does NumPy improve performance in numerical operations?
NumPy uses optimized C and Fortran libraries, allowing for faster execution of operations on large datasets compared to standard Python lists.What is the purpose of the Plotly library?
Plotly is a graphing library that enables the creation of interactive visualizations and plots, making it easy to visualize data in a web-based format.What types of visualizations can be created using Plotly?
Plotly supports a variety of visualizations, including line charts, scatter plots, bar charts, heatmaps, and 3D plots.How does SciPy relate to NumPy?
SciPy is built on top of NumPy and provides additional functionality for scientific and technical computing, including modules for optimization, integration, interpolation, and statistics.What are some common use cases for SciPy?
SciPy is commonly used for tasks such as solving differential equations, performing numerical integration, and conducting statistical analysis.How can NumPy arrays be beneficial for data manipulation?
NumPy arrays allow for efficient storage and manipulation of large datasets, enabling element-wise operations and broadcasting.What is the significance of the
ndarray
object in NumPy?
Thendarray
object is the core data structure in NumPy, representing a multidimensional array that can hold elements of the same type.Can Plotly be used for creating static plots?
Yes, Plotly can create static plots, but its primary strength lies in generating interactive visualizations that can be embedded in web applications.What improvements do these libraries bring to data analysis and visualization in Python?
These libraries provide powerful tools for efficient data manipulation, advanced mathematical computations, and high-quality visualizations, significantly enhancing the capabilities of data analysis in Python.
📌 Python Programming Lab – Complete Guide
Welcome to the Python Programming Lab! This comprehensive lab series is designed to provide a solid foundation in Python programming through practical exercises and hands-on learning. From basic calculations to advanced concepts like file handling, modules, and GUI programming, this lab covers it all. Let’s dive into what you’ll be learning throughout this lab course.
🔍 Week 1: Introduction to Python Basics
In the first week, you will explore fundamental Python concepts aimed at building a strong foundation for your programming journey.
- Getting Started with Python: Visit the Python Official Website to explore documentation and use the
help()
function in the interpreter. - Python as a Calculator: Learn how to perform basic arithmetic operations like addition, subtraction, multiplication, and division.
- Calculating Compound Interest: Write a program to calculate compound interest using the formula with given principal, rate, and time.
- Distance Calculation: Compute the distance between two points using the distance formula.
- Reading User Details: Write a program to collect and print user details like name, address, email, and phone number.
🔍 Week 2: Python Loops and Conditional Statements
This week focuses on using loops and conditional statements effectively.
- Pattern Generation: Print a triangle pattern using nested loops.
- Character Identification: Write a program to identify whether the input is a digit, lowercase, uppercase, or special character.
- Fibonacci Sequence Generation: Use a
while
loop to generate the Fibonacci series. - Prime Numbers Identification: Find all prime numbers within a specified range using the
break
statement.
🔍 Week 3: Data Structures and Functions
Dive into data structures and creating functions to enhance your programming skills.
- Converting Lists and Tuples to Arrays: Understand how to convert different data structures.
- Finding Common Values: Compare two arrays to find common values.
- Calculating GCD: Create a function to calculate the greatest common divisor (GCD) of two numbers.
- Palindrome Checker: Write a function that checks if a given string is a palindrome.
🔍 Week 4: Advanced Functions and String Manipulation
This week emphasizes sorting, handling duplicate elements, and manipulating strings effectively.
- Checking Sorted Lists: Write a function to check if a list is sorted.
- Handling Duplicates: Create functions to detect and remove duplicates from lists.
- Dictionary Inversion: Write a program to swap keys and values in a dictionary.
- String Manipulation: Add commas between characters, remove words from strings, and convert sentences to title case without using built-in functions.
- Binary String Generation: Use recursion to generate all binary strings of a specified length.
🔍 Week 5: Working with Matrices and Modules
Learn to work with matrices and create custom modules for various applications.
- Matrix Operations: Define, print, add, and multiply square matrices using Python.
- Creating Modules: Build modules using geometrical shapes and their operations.
- Exception Handling: Implement exception handling for robust error management.
🔍 Week 6: Object-Oriented Programming and Validation
This week focuses on using classes, inheritance, and validation techniques.
- Drawing Shapes with Classes:
- Create classes for rectangles, points, and circles, and draw them on a canvas.
- Add colors and attributes to these shapes to enhance visualization.
- Method Resolution Order (MRO): Demonstrate MRO in multiple inheritance scenarios.
- Data Validation: Write programs to validate phone numbers and email addresses.
🔍 Week 7: File Handling and Text Processing
Master file handling techniques and analyzing text data.
- File Merging: Combine the contents of two files into a new file.
- Word Search: Create a function to find specific words in a file.
- Word Frequency Analysis: Identify the most frequent words in a text file.
- Text Statistics: Count words, vowels, blank spaces, lowercase, and uppercase letters in a file.
🔍 Week 8: Python Libraries and GUI Programming
Explore advanced Python libraries and build simple graphical user interfaces.
- NumPy, Plotly, and Scipy: Learn how to install and use these powerful libraries for data analysis and visualization.
- Digital Logic Gates: Implement logic gate operations such as AND, OR, NOT, and EX-OR.
- Adder Circuits: Create programs for Half Adders, Full Adders, and Parallel Adders.
- GUI Programming: Build a simple window wizard with text labels, input fields, and buttons using Python’s GUI tools.
🌟 Conclusion:
The Python Programming Lab R23 provides you with a strong foundation in Python programming through a wide range of exercises, from basic concepts to advanced topics. By the end of this lab, you will have gained valuable skills in data processing, file handling, OOP, modules, and GUI development. Start coding and enhance your Python skills! 🚀