VNSGU BCA Sem 2: Programming Skills - Advanced (204_02) Practical Solutions - April 2025 Set E
Paper Details
- Subject: Programming Skills - Advanced (PKUP)
- Subject Code: 204_02
- Set: E
- Semester: 2
- Month/Year: April 2025
- Max Marks: 25
- Time Recommendation: 45 Minutes
- Paper: View Paper | Download PDF
Questions & Solutions
All questions are compulsory
Q1A: Student Data Pipeline
Max Marks: 20
Using Python, perform the following tasks for STUDENT data management:
- Create a dictionary (or a set of sets) containing details of students with the following fields: STUDENT_ID, NAME, COURSE, MARKS, ADMISSION_YEAR. Add at least 10 student records.
- Convert the dictionary into a pandas DataFrame.
- Save the DataFrame as a CSV file named
student_data.csv. - Load the CSV file and display: a) All students enrolled in the "B.Sc. Computer Science" course b) Students who scored more than 80 marks c) Students admitted before 2020
1. Dictionary & DataFrame Creation
Initialize the student registration database and convert it into a Pandas DataFrame.
Hint
Define a dictionary where each key matches the required columns. Use pd.DataFrame(student_dict) to create the table.
View Solution & Output
import pandas as pd
# [1] Create dictionary with student details
student_dict = {
'STUDENT_ID': [101, 102, 103, 104, 105, 106, 107, 108, 109, 110],
'NAME': ['Amit', 'Priya', 'Rahul', 'Sia', 'Aryan', 'Neha', 'Vikram', 'Sneha', 'Karan', 'Mira'],
'COURSE': ['B.Sc. Computer Science', 'BCA', 'B.Sc. Computer Science', 'B.Com', 'B.Sc. Computer Science', 'BBA', 'BCA', 'B.Sc. Computer Science', 'BBA', 'BCA'],
'MARKS': [85, 78, 92, 70, 88, 65, 81, 75, 95, 82],
'ADMISSION_YEAR': [2019, 2021, 2018, 2022, 2019, 2020, 2021, 2018, 2023, 2019]
}
# [2] Convert dictionary into pandas DataFrame
df = pd.DataFrame(student_dict)
print("DataFrame successfully initialized.")
print(df.head())
Step-by-Step Explanation:
- Initialization: Import
pandasand define thestudent_dictdictionary containing records for 10 students. - Logic Flow: Convert the dictionary into a tabular structure using
pd.DataFrame()and assign it to the variabledf. - Completion: Use
df.head()to display the first few rows to verify the data was loaded correctly.
2. File Storage (CSV)
Export the student records to a CSV file.
Hint
Use df.to_csv('student_data.csv', index=False).
View Solution & Output
# [3] Save DataFrame as CSV file
df.to_csv('student_data.csv', index=False)
print("File 'student_data.csv' created successfully.")
Step-by-Step Explanation:
- Initialization: Use the active DataFrame
dfcontaining student information. - Logic Flow: Save the DataFrame to a local file named
'student_data.csv'usingto_csv()withindex=Falseto skip row labels. - Completion: A success message confirms the creation of the CSV file on disk.
3. Data Loading & Analytics
Load the CSV and search for specific students based on course, marks, and year.
Hint
Use string matching for courses and numeric comparisons for marks and years.
View Solution & Output
# [4] Load CSV file and perform queries
load_df = pd.read_csv('student_data.csv')
# Query 1: B.Sc. Computer Science
print("\n[a] Students in B.Sc. Computer Science:")
print(load_df[load_df['COURSE'] == 'B.Sc. Computer Science'])
# Query 2: Marks > 80
print("\n[b] Top Scorers (Marks > 80):")
print(load_df[load_df['MARKS'] > 80])
# Query 3: Admission Year < 2020
print("\n[c] Admitted Before 2020:")
print(load_df[load_df['ADMISSION_YEAR'] < 2020])
Step-by-Step Explanation:
- Initialization: Load the records from
'student_data.csv'usingpd.read_csv()into a new DataFrame. - Logic Flow: Apply boolean indexing to filter the dataset based on course name, score thresholds, and admission years.
- Completion: Display the query results to help analyze student enrollment and performance.
Q2: Viva Preparation
Max Marks: 5
Potential Viva Questions
- Q: How can you find the highest marks in the DataFrame?
- A: Use
df['MARKS'].max().
- A: Use
- Q: What is the purpose of the
shapeattribute?- A: It returns a tuple representing the dimensionality of the DataFrame (rows, columns).
- Q: How do you sort students by their names?
- A: Use
df.sort_values(by='NAME').
- A: Use
- Q: How do you calculate the mean marks for each course?
- A: Use
df.groupby('COURSE')['MARKS'].mean().
- A: Use
- Q: What is the difference between
count()andvalue_counts()?- A:
count()returns the number of non-null values in each column, whilevalue_counts()returns the frequency of unique values in a single column.
- A:
- Q: How do you select rows where Name starts with 'A'?
- A: Use
df[df['NAME'].str.startswith('A')].
- A: Use
Common Pitfalls
- Exact String Matches: If the course is "B.Sc Computer Science" (missing dot), the filter
== 'B.Sc. Computer Science'will return no results. - Column Availability: Ensure the CSV is loaded correctly before filtering to avoid
KeyError.
Quick Navigation
Related Solutions
| Set | Link |
|---|---|
| Set A | Solutions |
| Set B | Solutions |
| Set C | Solutions |
| Set D | Solutions |
| Set E | Current Page |
| Set F | Solutions |
Last Updated: April 2026