Medium-Level Practical Questions on NumPy and
Pandas
Q1. Sales Data Cleaning (Pandas)
You are given a sales dataset with the following columns: ['Date', 'Store_ID', 'Product', 'Quantity',
'Revenue'].
Some issues exist:
- The Date column is stored as a string.
- Some Quantity values are negative.
- There are missing values in the Revenue column.
Task:
1. Convert Date into a proper datetime format.
2. Replace negative Quantity values with their absolute values.
3. Fill missing Revenue values using: Quantity × average price of that product.
Q2. Stock Market Analysis (NumPy + Pandas)
You have a DataFrame df containing daily stock prices with columns: ['Date', 'Open', 'High', 'Low',
'Close', 'Volume'].
Task:
1. Using NumPy, calculate the daily return as: (Close - Open) / Open
2. Add this as a new column Daily_Return in the DataFrame.
3. Find the top 5 days with the highest positive return and the top 5 days with the worst negative
return.
Q3. Student Performance (Pandas)
You have a DataFrame of student exam scores: ['Student_ID', 'Math', 'Science', 'English', 'History'].
Task:
1. Compute each student’s average score and add it as a new column.
2. Rank students by their average score (highest = rank 1).
3. Find the subject in which students scored the lowest average marks overall.
Q4. Weather Data Transformation (NumPy + Pandas)
You have a CSV file [Link] with columns: ['City', 'Date', 'Temperature_C'].
Task:
1. Convert the Temperature_C column to Fahrenheit using NumPy’s vectorized operations: F = C ×
(9/5) + 32
2. Add it as a new column Temperature_F.
3. Group the data by City and find the day with the highest temperature (Fahrenheit) for each city.