Python for Data Science: Chapter 5: NumPy and Pandas Libraries: Anna University Part A Two Marks Important Questions and Answers
Python for Data Science
Chapter 5: NumPy and Pandas Libraries
Two Marks Questions with Answers
1. What
is numPy ? Enlist its usefulness.
Answer: The
NumPy is a python library which is used to perform numerical calculations. It
is normally used for working with arrays
NumPy
is generally used for
1.
Data science
2.
Machine learning
3.
Scientific computing
4.
Image and signal processing.
2. If I
want to use numpy functionality in my Python program, how can I do so?
Answer: For
using the numpy functionality in a Python program, we have to import the numpy
library. The code for importing it is (r)inglenil.qa xalom vod
import numpy as np
After this import statement, we can use NumPy
functions and objects by calling them with np.
3. What
is the purpose of copyto function ?
Answer: When
we want to copy one array to another array then the copyto function is used.
For
example ‒
import numpy as np
a = np.array(11,22,33])
b = np.array([10,20,30])
np.copyto(a,b)
print(a) //Output: [10 20 30]
4. How to
compute the determinant of a matrix using Python ?
Answer: We
can find the determinant of a matrix using the function linalg.det() which is
supported by numpy.
Syntax:
numpy.linalg.det(matrix)
For
example ‒
import numpy as np
x = np.matrix("6,2,1;4,‒2,4;2,9,8")
print(x)
print("The determinant of the matrix is...")
det_mat = np.linalg.det(x)
print(det_mat)
5. Can we
find inverse of a matrix using Python library? If yes, how?
Answer: In
order to find the inverse of a matrix in Python, there is a function available
in numpy
library.
It is ‒
numpy.linalg.inv()
Syntax
numpy.linalg.inv(matrix)
The
matrix can be stored in some variable x as follows‒
x = numpy.matrix ("1,2,3,4,5,6,7,2,9")
The
complete Python program can be written as follows ‒
Python program
import numpy as np
x = np.matrix ("1,2,3;4,5,6;7,2,9")
print(x)
print("The inverse of the matrix is...")
inv matrix = np.linalg.inv(x)
print(inv_matrix)
6. Write
a Python program to get a random value from the given array.
Answer: We
can obtain a random value from the given array. The choice() function is used
to choose this random number.
Python code
from numpy import random
num = random.choice([2,3,5,8,13,21])
print("The random number from the array is ...")
print(num)
7. What
is Pandas? Enlist its features.
Answer: Pandas
is an open‒source library provided by Python. It is used in data science, data
analysis and machine learning activities. Pandas is a data manipulation package
in Python for tabular data. It has functions for analyzing, cleaning, exploring
and manipulating data.
Features
of Pandas
1)
It represents the data in tabular form.
2)
It can perform quick and efficient data manipulation and analysis.
3)
It can load data from different file formats into in‒memory data objects.
4)
It can merge and join two datasets easily.
5)
It provides time‒series functionality.
6)
It can pivot and reshape data sets.
8. What
is series and dataframes in Pandas ?
Answer: The
Pandas series is like a column in a table. It is basically a one dimensional
array holding data of any type. Using the pd.Series
function, the series can be created. A DataFrame is a multi‒ dimensional data
structure in which data is arranged in the form of rows and columns. Series is
like a column and DataFrame is the whole table.
9. What
is purpose of loc and iloc functions?
Answer: The
loc and iloc are two functions in Pandas that are used to slice a dataset in a
Pandas DataFrame.
The
loc method is used to select the
data from the dataframe. Using this function we can pass the condition for
selection of data. We can select a single row using the index label.
print(df.loc['s4'])
10. What
is the use of fillna function ?
Answer: For
filling the missing data by some value we use the function fillna.
11. What
is hierarchical indexing ?
Answer: Hierarchical
indexing is also known as multiple indexing. The multiple index is an array of
tuples where each tuple is unique. We can create a MultiIndex from array of
arrays using from_arrays() method.
Python for Data Science: Chapter 5: NumPy and Pandas Libraries : Tag: Computer Programming, Python, Data Science : Python for Data Science - NumPy and Pandas Libraries: Two Marks Important Questions and Answers
Python for Data Science
AD25201 2nd Semester AIDS Dept | 2025 Regulation | 2nd Semester 2025 Regulation
English Essentials II
EN25C02 2nd Semester | 2025 Regulation | 2nd Semester 2025 Regulation
Tamils and Technology தமிழர்களும் தொழில்நுட்பமும்
UC25H02 2nd Semester | 2025 Regulation | 2nd Semester 2025 Regulation
Linear Algebra
MA25C02 2nd Semester | 2025 Regulation
Applied Physics (CSIE) II
PH25C03 2nd Semester AIDS, CSE, IT, CSE(CY) Dept | 2025 Regulation | 2nd Semester 2025 Regulation
Digital Principles and Computer Organization
CS25C06 2nd Semester AIDS, CSE, IT, CSE(CY) Dept | 2025 Regulation | 2nd Semester 2025 Regulation
Basic Electrical and Electronics Engineering
EE25C01 2nd Semester | 2025 Regulation | 2nd Semester 2025 Regulation
Python for Data Science
AD25201 2nd Semester AIDS Dept | 2025 Regulation | 2nd Semester 2025 Regulation
Re-Engineering for Innovation
ME25C05 2nd Semester | 2025 Regulation | 2nd Semester 2025 Regulation
Python for Data Science - Laboratory
AD25201 2nd Semester AIDS Dept | 2025 Regulation | 2nd Semester 2025 Regulation