Skip to content

VNSGU BCA Sem 2: Programming Skills - Advanced (204_02) Practical Solutions - 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: 1. 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. 2. Convert the dictionary into a pandas DataFrame. 3. Save the DataFrame as a CSV file named student_data.csv. 4. 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.

flowchart TD
dict[Student Dictionary]
df[Pandas DataFrame]
conv[pd.DataFrame Conversion]

dict --> conv
conv --> df
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: 1. Initialization: Import pandas and define the student_dict dictionary containing records for 10 students. 2. Logic Flow: Convert the dictionary into a tabular structure using pd.DataFrame() and assign it to the variable df. 3. 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).

flowchart TD
df[Pandas DataFrame]
save[Save to CSV]
file[student_data.csv]

df --> save
save --> file
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: 1. Initialization: Use the active DataFrame df containing student information. 2. Logic Flow: Save the DataFrame to a local file named 'student_data.csv' using to_csv() with index=False to skip row labels. 3. 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.

flowchart TD
load[Load read_csv]
filter[Apply Filters]
show[Show Results]

load --> filter
filter --> show
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: 1. Initialization: Load the records from 'student_data.csv' using pd.read_csv() into a new DataFrame. 2. Logic Flow: Apply boolean indexing to filter the dataset based on course name, score thresholds, and admission years. 3. Completion: Display the query results to help analyze student enrollment and performance.

Q2: Viva Preparation

Max Marks: 5

Potential Viva Questions
  1. Q: How can you find the highest marks in the DataFrame?
  2. A: Use df['MARKS'].max().
  3. Q: What is the purpose of the shape attribute?
  4. A: It returns a tuple representing the dimensionality of the DataFrame (rows, columns).
  5. Q: How do you sort students by their names?
  6. A: Use df.sort_values(by='NAME').
  7. Q: How do you calculate the mean marks for each course?
  8. A: Use df.groupby('COURSE')['MARKS'].mean().
  9. Q: What is the difference between count() and value_counts()?
  10. A: count() returns the number of non-null values in each column, while value_counts() returns the frequency of unique values in a single column.
  11. Q: How do you select rows where Name starts with 'A'?
  12. A: Use df[df['NAME'].str.startswith('A')].

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

Set Link
Set A Solutions
Set B Solutions
Set C Solutions
Set D Solutions
Set E Current Page
Set F Solutions

Last Updated: April 2025