Data Structure using Python 22395
1. What is the use of Numpy package and explain different methods.
NumPy is a powerful Python library used for numerical computing. It provides support for
multidimensional arrays (matrices) and a collection of mathematical functions to operate on
these arrays efficiently. NumPy is widely used in scientific computing, data analysis, machine
learning, and other domains where numerical computations are common.
• numpy.array(): Create a NumPy array from a Python list or tuple.
• numpy.zeros(): Create an array filled with zeros of specified shape.
• numpy.linspace(): Generate evenly spaced numbers over a specified interval.
• numpy.mean(): Compute the arithmetic mean along a specified axis.
• numpy.dot(): Compute the dot product of two arrays.
2. What is the use of Matplotlib package and explain different methods.
Matplotlib is a popular Python library used for creating static, animated, and interactive
visualizations. It provides a wide range of plotting functions and customization options for
generating high-quality graphs, charts, and figures.
• matplotlib.pyplot.plot(): Create a line plot to visualize data points connected
by straight line segments.
• matplotlib.pyplot.scatter(): Generate a scatter plot to visualize the relationship
between two variables by plotting individual data points.
• matplotlib.pyplot.bar(): Plot vertical bars to represent the distribution or
comparison of categorical data.
• matplotlib.pyplot.hist(): Generate a histogram to visualize the frequency
distribution of numerical data by dividing it into bins.
• matplotlib.pyplot.imshow(): Display an image (2D array) or a heatmap using
color gradients to represent the intensity of values.
3. What is the use of scipy package and explain different methods.
The SciPy library is built on top of NumPy and provides additional functionality for scientific
computing. It includes modules for optimization, integration, interpolation, linear algebra,
statistics, signal processing, and more.
• scipy.constants.physical_constants(): Retrieve physical constants like the
speed of light or the Planck constant.
V2V EdTech LLP
Data Structure using Python 22395
• scipy.stats.describe(): Compute descriptive statistics like mean, variance,
skewness, and kurtosis.
• scipy.linalg.det(): Compute the determinant of a square matrix.
• scipy.spatial.distance.euclidean(): Compute the Euclidean distance between
two points in n-dimensional space.
• scipy.signal.convolve(): Perform convolution between two arrays.
4. What is the use of Numpy package and explain different methods.
NumPy is a fundamental Python library for numerical computing, offering support for large,
multi-dimensional arrays and matrices, along with an extensive collection of mathematical
functions to operate on these arrays efficiently.
• numpy.array(): Create a NumPy array from a Python list or tuple.
• numpy.zeros(): Create an array filled with zeros of specified shape.
• numpy.linspace(): Generate evenly spaced numbers over a specified interval.
• numpy.mean(): Compute the arithmetic mean along a specified axis.
• numpy.dot(): Compute the dot product of two arrays.
5. What is the use of pandas package and explain different methods.
Pandas is a powerful Python library used for data manipulation and analysis. It provides data
structures like DataFrame and Series, along with tools for reading and writing data from
various file formats, handling missing data, reshaping, grouping, and aggregating data, and
much more.
• pandas.DataFrame(): Create a DataFrame from data, such as a dictionary, a list
of dictionaries, or a NumPy array.
• DataFrame.head(): Retrieve the first few rows of a DataFrame to quickly
inspect the data.
• DataFrame.info(): Display a concise summary of the DataFrame including its
data types, non-null values, and memory usage.
• DataFrame.describe(): Generate descriptive statistics (count, mean, std
deviation, etc.) for numerical columns in the DataFrame.
• DataFrame.to_csv(): Write the DataFrame to a CSV (comma-separated values)
file.
6. List standard built-in modules
V2V EdTech LLP
Data Structure using Python 22395
• math: Mathematical functions and constants.
• random: Generate pseudo-random numbers.
• os: Operating system interface for interacting with the operating system.
• sys: System-specific parameters and functions.
• datetime: Date and time manipulation.
• json: JSON encoding and decoding.
• csv: CSV file reading and writing.
• re: Regular expression operations.
• urllib: URL handling utilities.
• collections: Additional data structures beyond the built-in ones like lists,
tuples, and dictionaries.
• time: Time-related functions.
• argparse: Command-line argument parsing.
• socket: Low-level networking interface.
• sqlite3: SQLite database interface.
• gzip, zipfile: Modules for working with compressed files.
• io: Core tools for working with streams.
• hashlib: Secure hash and message digest algorithms.
• pickle: Object serialization and deserialization.
• itertools: Functions for creating iterators for efficient looping.
• subprocess: Run external processes.
7. Explain list and its operations along with its basic built in operations.
A list is a versatile and mutable ordered collection of items. Lists can contain elements of
different data types and can dynamically grow or shrink in size. They are defined by
enclosing comma-separated values within square brackets [ ].
Operations:
• Creating a List: Define a list using square brackets [ ].
• Accessing Elements: Retrieve individual elements using indexing.
V2V EdTech LLP
Data Structure using Python 22395
• Slicing: Extract a portion of the list using the slicing operator :.
• Updating Elements: Modify the value of elements using indexing.
• Appending: Add an element to the end of the list using the append() method.
• Extending: Add elements from another list to the end of the list using the
extend() method.
• Removing Elements: Remove the first occurrence of a specified value using
the remove() method.
• Popping: Remove and return an element at a specified index using the pop()
method.
• Length: Get the number of elements in the list using the len() function.
• Membership Check: Check if an element exists in the list using the in
keyword.
• Concatenation: Concatenate two lists using the + operator.
• Copying: Create a copy of the list using slicing or the copy() method.
8. Explain tuples and its operations along with its basic built in operations.
Immutable ordered collections of elements, defined using parentheses ( ).
• Creating a Tuple: Define a tuple using parentheses ( ).
• Accessing Elements: Retrieve individual elements using indexing.
• Slicing: Extract a portion of the tuple using the slicing operator :.
• Length: Get the number of elements in the tuple using the len() function.
• Concatenation: Concatenate two tuples using the + operator.
• Repetition: Repeat a tuple using the * operator.
• Membership Check: Check if an element exists in the tuple using the in
keyword.
• Copying: Create a copy of the tuple using slicing or the tuple() constructor.
• len(): Get the length (number of elements) of a tuple.
• count(): Count the number of occurrences of a specified value in a tuple.
• index(): Return the index of the first occurrence of a specified value in a tuple.
V2V EdTech LLP
Data Structure using Python 22395
• sorted(): Return a new sorted list from the elements of the tuple.
• any(): Check if any element in the tuple is true.
9. Explain sets and its operations along with its basic built in operations.
Unordered collections of unique elements without duplicates, defined using braces { }.
• Creating a Set: Define a set using braces { } or the set() constructor.
• Adding Elements: Add an element to the set using the add() method.
• Removing Elements: Remove an element from the set using the remove() or
discard() method.
• Checking Membership: Check if an element exists in the set using the in
keyword.
• Length: Get the number of elements in the set using the len() function.
• Union: Get the union of two sets using the union() or | operator.
• Intersection: Get the intersection of two sets using the intersection() or &
operator.
• Difference: Get the difference between two sets using the difference() or -
operator.
10. Explain dictionaries and its operations along with its basic built in operations.
Unordered collections of key-value pairs defined using braces {}.
• Creating a Dictionary: Define a dictionary using braces {} or the dict()
constructor.
• Accessing Elements: Access values using keys.
• Adding or Updating Elements: Add or update key-value pairs using
assignment.
• Removing Elements: Remove a key-value pair using the del keyword or the
pop() method.
• Checking Membership: Check if a key exists in the dictionary using the in
keyword.
• Length: Get the number of key-value pairs in the dictionary using the len()
function.
V2V EdTech LLP
Data Structure using Python 22395
• Keys: Get a view of all keys in the dictionary using the keys() method.
V2V EdTech LLP