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

Machine Larning

The document contains a series of assignments focused on Python data science, covering topics such as NumPy, Matplotlib, Pandas, and Seaborn. Each assignment includes questions and answers that explain key concepts, functions, and differences between various data structures and visualization techniques. It serves as a comprehensive guide for understanding the basics and advanced features of these libraries.

Uploaded by

diggu542
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)
4 views4 pages

Machine Larning

The document contains a series of assignments focused on Python data science, covering topics such as NumPy, Matplotlib, Pandas, and Seaborn. Each assignment includes questions and answers that explain key concepts, functions, and differences between various data structures and visualization techniques. It serves as a comprehensive guide for understanding the basics and advanced features of these libraries.

Uploaded by

diggu542
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

Python Data Science Assignments:

Questions & Answers

Assignment 1: Basics of Python, NumPy, and Control


Statements
Q1: What is NumPy?
A: NumPy (Numerical Python) is a Python library used for numerical computations. It
provides support for large, multi-dimensional arrays and matrices, plus mathematical
functions for fast operations.

Q2: How do you create a NumPy array?


A: By using the function np.array() and passing a list or tuple.
Example: arr = np.array([1, 2, 3])

Q3: What is the difference between a list and a NumPy array?


A: Lists are general containers for different data types, slower for numerical operations.
NumPy arrays are optimized for numerical data, support vectorized operations, and are
more memory efficient.

Q4: How to check the shape of a NumPy array?


A: Using the .shape attribute, e.g., arr.shape

Q5: How do you create a NumPy array filled with zeros?


A: Using np.zeros(shape), where shape is a tuple like (3, 4).

Q6: Explain the syntax of an if-else statement in Python.


A:

python
CopyEdit
if condition:
# code if True
else:
# code if False

Q7: What are loops? Name two types in Python.


A: Loops repeat code multiple times. Two types:
 for loop (iterate over sequence)
 while loop (repeat while condition is True)
Q8: What is the purpose of break, continue, and pass?
A:
 break stops the loop.
 continue skips current iteration.
 pass does nothing; placeholder.

Q9: Difference between for and while loops?


A: for loops run a fixed number of times over a sequence; while loops run until a
condition becomes False.

Assignment 2: Advanced NumPy Concepts


Q1: How to create an array with values 1 to 10?
A: np.arange(1, 11)

Q2: What does np.linspace() do?


A: Generates evenly spaced numbers between two limits.

Q3: How to find and change the shape of an array?


A:
 Find shape: arr.shape
 Change shape: arr.reshape(new_shape)

Q4: How to find the data type of a NumPy array?


A: Using arr.dtype

Q5: What is broadcasting in NumPy?


A: It allows arithmetic operations on arrays of different shapes by automatically
expanding the smaller array.

Q6: List advantages of NumPy arrays over lists.


A: Faster computations, less memory, supports vectorized operations, provides
multidimensional arrays.

Q7: Different ways to create NumPy arrays?


A:
 From lists: np.array([1, 2, 3])
 Using functions: np.zeros(), np.ones(), np.empty(), np.arange(),
np.linspace()

Q8: How does slicing work in NumPy?


A: Access parts of arrays using arr[start:stop].

Q9: Explain vectorized operations.


A: Operations applied element-wise to arrays without explicit loops, improving speed.
Assignment 3: Matplotlib Basics
Q1: What does plt.show() do?
A: Displays the plot window.

Q2: How to plot a simple line graph?


A: Use plt.plot(x, y) where x and y are lists or arrays of coordinates.

Q3: How to create multiple plots in one figure?


A: Use plt.subplot(rows, cols, plot_number).

Q4: How to plot a sine wave?


A: Use NumPy to generate x values and calculate sine, then plot.
Example:
python
CopyEdit
x = np.linspace(0, 2*np.pi, 100)
y = np.sin(x)
plt.plot(x, y)
plt.show()

Q5: How to change line color and style?


A: Use parameters like color='red', linestyle='--' in plt.plot().

Q6: Difference between plt.scatter() and plt.plot()?


A: scatter() plots discrete points; plot() connects points with lines.

Q7: What’s the difference between a histogram and a bar chart?


A: Histogram shows frequency distribution of continuous data; bar chart compares
categorical data.

Assignment 4: Pandas Data Analysis


Q1: What does df.head() do?
A: Returns the first 5 rows of the DataFrame.

Q2: Define a Pandas Series.


A: A one-dimensional labeled array holding any data type.

Q3: Difference between Series and DataFrame?


A: Series is 1D, DataFrame is 2D (rows and columns).

Q4: What info does df.info() provide?


A: Summary including column data types, non-null counts, and memory usage.
Q5: What is axis=0 and axis=1?
A:
 axis=0 applies operation along rows (down columns).
 axis=1 applies operation along columns (across rows).

Q6: How to read a CSV file?


A: pd.read_csv('filename.csv')

Q7: How to filter rows where salary > 50000?


A: df[df['salary'] > 50000]

Q8: How to add a new column?


A: df['new_column'] = values

Q9: How to handle missing data in Pandas?


A: Use dropna() to remove or fillna(value) to replace missing values.

Assignment 5: Seaborn Visualization


Q1: What is Seaborn?
A: A Python visualization library built on Matplotlib for easier and prettier statistical
plots.

Q2: How to create a histogram in Seaborn?


A: sns.histplot(data=df, x='column_name')

Q3: Difference between Seaborn and Matplotlib?


A: Seaborn provides higher-level interface, better styles and color palettes, simpler code
for complex plots.

Q4: How to create a box plot?


A: sns.boxplot(x='category', y='value', data=df)

Q5: How to plot relationships between two variables?


A: Use sns.scatterplot(x='var1', y='var2', data=df)

Q6: When to use boxplot vs violinplot?


A: Boxplot summarizes data with quartiles; violinplot shows distribution shape as well.

Q7: What are hue, style, and size parameters in Seaborn?


A: Used to add more data dimensions visually by color (hue), marker style (style), or
marker size (size).

You might also like