0% found this document useful (0 votes)
8 views4 pages

What Is Numpy, and Why Is It Important For Data Analysis in Python?

these are my semester documents

Uploaded by

mohdash204
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)
8 views4 pages

What Is Numpy, and Why Is It Important For Data Analysis in Python?

these are my semester documents

Uploaded by

mohdash204
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
You are on page 1/ 4

1.

What is NumPy, and why is it important for data analysis in


Python?

NumPy (Numerical Python) is a library for efficient numerical computation. It


provides support for multi-dimensional arrays and mathematical functions. It
is important for data analysis because it enables fast data processing,
supports linear algebra, and integrates well with other data science libraries
like Pandas.

2. How do you create a NumPy array from a Python list? Provide


an example.

You can create a NumPy array using the numpy.array() method.

Import numpy as np

My_list = [1, 2, 3]

Np_array = np.array(my_list)

Print(np_array) # Output: [1 2 3]

3. What is a Pandas Series? How is it different from a NumPy


array?

A Pandas Series is a one-dimensional labeled array capable of holding data of


any type.
Difference:

A Series has labels (index) for each data element, whereas a NumPy array
only holds data without labels.

Example:

Import pandas as pd

Series = pd.Series([10, 20, 30], index=[‘a’, ‘b’, ‘c’])

Print(series) # a 10, b 20, c 30

4. What is the purpose of the drop() method in Pandas? Write an


example.

The drop() method removes specified rows or columns from a DataFrame.

Example:

Import pandas as pd

Data = {‘A’: [1, 2], ‘B’: [3, 4]}

Df = pd.DataFrame(data)

Df = df.drop(‘A’, axis=1) # Drop column ‘A’

Print(df)
5. What happens when missing data is encountered in a Pandas
DataFrame? How can it be handled?

When missing data is found, it is represented as NaN. It can be handled by:

Removing rows/columns with missing data (dropna()).

Filling missing values with a specific value (fillna()).

Example:

Df.fillna(0) # Replaces all NaN values with 0

6. What happens when you add a scalar to an array?

Adding a scalar to an array applies the scalar to each element of the array
(broadcasting).

Example:

Import numpy as np

Arr = np.array([1, 2, 3])


Result = arr + 5 # Output: [6 7 8]

7. How do you access the second element of a 1D array?

Use indexing to access elements. In a 1D array, indexing starts from 0.

Example:

Arr = np.array([10, 20, 30])

Print(arr[1]) # Output: 20

You might also like