Module 19: Practice & Interview Q&A
Practice your data science skills and check typical interview questions regarding NumPy, Pandas, and Matplotlib.
19.5.1 Practice Exercises
- NumPy Math:
Create a NumPy array from the list
[10, 15, 20, 25, 30]. Write a Python script to compute the standard deviation and the mean of this array. - Pandas Columns & Filtering:
Create a CSV file
students.csvwith three columns:Name,Age,Score. Write a Pandas script to:- Read the CSV file.
- Add 5 bonus points to all student scores (
Score + 5). - Filter out and print only the students who scored above 80.
- Visualization:
Plot a bar chart showing the scores of these students using Matplotlib and save the plot as
student_scores.png.
19.5.2 Placement Q&A (Interview Prep)
Test your knowledge with this quick interactive quiz:
💡 Practice Quiz
Why are NumPy arrays faster than standard Python lists?
Click on the questions below to reveal more answers:
Q1. Why are NumPy arrays faster than normal Python lists?
NumPy arrays are faster because:
- They store elements of the same data type (homogeneous), allowing contiguous memory allocation.
- They support vectorization (applying operations to the whole array at once) without requiring slow Python
forloops. - They avoid the memory overhead of storing individual Python object references.
Q2. What is the difference between a Series and a DataFrame in Pandas?
- Series: A one-dimensional labeled array capable of holding data of any type. It represents a single column of data.
- DataFrame: A two-dimensional labeled data structure with columns of potentially different types, resembling an Excel table or database table.
Q3. What does df.describe() do in Pandas?
The describe() method compiles a quick summary of the numerical columns in a DataFrame, displaying statistical metrics such as count, mean, standard deviation, minimum, maximum, and the 25%, 50%, and 75% percentiles.
Q4. Why is plt.savefig() called before plt.show() in Matplotlib?
When plt.show() is called, it clears the current figure state from memory to release resources. If you call plt.savefig() after plt.show(), the saved image will be blank because the graph canvas has already been reset.