0% found this document useful (0 votes)
3 views2 pages

NumPy and Pandas for Data Analysis

The document provides instructions on loading the NumPy library in Python and explains its purpose in computational science, particularly in engineering applications. It includes examples of retrieving elements from a NumPy array and slicing it. Additionally, it describes two Pandas DataFrame methods, .dropna() and .drop(0), which are used for data cleaning by removing missing values and specific rows, respectively.

Uploaded by

ajoceasor
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views2 pages

NumPy and Pandas for Data Analysis

The document provides instructions on loading the NumPy library in Python and explains its purpose in computational science, particularly in engineering applications. It includes examples of retrieving elements from a NumPy array and slicing it. Additionally, it describes two Pandas DataFrame methods, .dropna() and .drop(0), which are used for data cleaning by removing missing values and specific rows, respectively.

Uploaded by

ajoceasor
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

PART I

(i)Provide the standard, idiomatic Python code for loading the NumPy library. Briefly
describe the main purpose of NumPy in computational science and engineering.

Loading NumPy and its Purpose


Standard idiomatic Python code for loading the NumPy library:

import numpy as np

NumPy (Numerical Python) is a core Python library used for numerical and scientific
computing. It provides efficient N-dimensional array objects, fast vectorized operations,
and tools for linear algebra, Fourier transforms, and statistical analysis. In civil and
structural engineering, NumPy is applied in handling large datasets, matrix operations in
finite element analysis, and numerical modeling of engineering systems.

(j)Given a NumPy array A=[Link]([10,20,30,40,50]), write the Python expression(s)

required to perform the following:

i. Retrieve the first element (10) using its index.

ii. Slice the array to return the sub-array [20,30,40].

Array Operations using NumPy


Given array: A = [Link]([10, 20, 30, 40, 50])

i. Retrieving the first element (10) using its index:

A[0]

ii. Slicing the array to return the sub-array [20, 30, 40]:

A[1:4]

Python uses zero-based indexing, so A[0] returns the first element. The slice A[1:4]
returns elements from index 1 up to, but not including, index 4.
(i)What is the purpose of the following two Pandas DataFramemethods in data cleaning?

i. .dropna() ii. .drop(0)(when applied to a DataFrame where the first row is an index of 0)

Purpose of Pandas DataFrame Methods in Data Cleaning


i. .dropna():

Removes all rows (or columns) that contain missing (NaN) values. This method is used
to clean datasets by eliminating incomplete data entries, ensuring accurate analysis and
computations.

ii. .drop(0):

Removes the row or column with the specified label—in this case, the row with index 0.
It is used to delete the first row, often containing invalid or redundant information. This
method is used in data cleaning to eliminate specific rows, such as an unnecessary or
erroneous first row, based on its index label.

You might also like