CBSERanker

Loading

List of Practical Quetions Class 12 IP- Python and SQL

List of Practical Quetions Class 12 IP- Python and SQL

Pandas Series (Data Handling)

1. Create a Pandas Series from a dictionary where the keys are student names (‘Alice’, ‘Bob’, ‘Charlie’) and the values are their corresponding marks (85, 92, 78). Print the series.

2. Create a Pandas Series from a NumPy array np.array([10, 20, 30, 40, 50]). Print the series and its data type.

3. Given a Series s = pd.Series([12, 44, 65, 29, 19, 23, 88, 75, 53]), write a program to print all elements that are above the 75th percentile.

4. Create a Series object for the per capita income (in thousands) of four zones: North=45, South=38, East=29, West=41. Perform the operation to increase every zone’s income by 5%.

5. Given two Series s1 = pd.Series([2, 4, 6, 8]) and s2 = pd.Series([1, 3, 5, 7]), perform element-wise addition, subtraction, and multiplication.

6. For the Series s = pd.Series([33, 55, 65, 29, 19, 23]), find and print the sum of all values that end with the digit 3 or 5.

7. Create a Series from a scalar value 100 with an index of five elements: [‘a’, ‘b’, ‘c’, ‘d’, ‘e’]. Print the series.

Pandas DataFrame (Data Handling)

8. Create a DataFrame df using a nested list where the data is [[1, 'Ajay', 95], [2, 'Bjay', 85], [3, 'Cjay', 75]] with columns ['RollNo', 'Name', 'Marks']. Display the DataFrame.

9. For the DataFrame created in Q8, write code to:
a) Display only the ‘Name’ column.
b) Display the row at index 1.

10. Rename the columns of the DataFrame from Q8 to [‘ID’, ‘Student_Name’, ‘Score’] and then replace the name ‘Bjay’ with ‘Bijay’ in the ‘Student_Name’ column.

11. Filter the DataFrame from Q8 to display only the rows where the ‘Marks’ are greater than 80.

12. Create a DataFrame quarterly_sales with columns: ‘Category’, ‘Item_Name’, ‘Expenditure’. Populate it with at least 6 rows. Group the rows by ‘Category’ and print the total expenditure per category.

13. Create a DataFrame exam_result with data [[101, 'A', 87], [102, 'B', 92], [103, 'A', 78]] and columns ['RollNo', 'Class', 'Marks']. Write a program to display:
a) The row labels (index)
b) The column labels
c) The data types of each column
d) The dimensions (shape) of the DataFrame

14. Add a duplicate row to the exam_result DataFrame from Q13. Then write code to identify and remove these duplicate rows.

15. Save the exam_result DataFrame from Q13 to a CSV file named 'results.csv'. Then write a separate program to read this CSV file back into a new DataFrame and display it.

Data Visualization (Matplotlib)

16. Plot a line chart for the number of masks sold from the given medical store data. Customize the chart with a title, and labels for the x and y axes.

MonthMasks
March1500
April3500
May6500
June6700
July6000
August6800

17. Plot a multiple line chart on the same graph showing the sales trend of Masks, Sanitizer, and Hand wash from the full medical store dataset. Add a legend to distinguish the lines.

18. Using the quarterly_sales DataFrame from Q12, plot a bar chart showing the total expenditure for each item category.

19. Create a DataFrame from a CSV file of your choice (e.g., 'results.csv' from Q15) and plot a horizontal bar chart showing the marks of each student.

20. Generate 100 random numbers from a normal distribution. Plot a histogram of these numbers with 15 bins. Add a title and labels.

21. (Open Source Data) Download a dataset from data.gov.in (e.g., State-wise GDP). Load it into a Pandas DataFrame, clean it if necessary, and plot a pie chart showing the percentage contribution of the top 5 states.

SQL Data Management

For the following questions, use a table named Students with the structure:

  • StudentID INTEGER (Primary Key)
  • Name VARCHAR(255)
  • Marks INTEGER
  • Country VARCHAR(100)

Sample Data:

StudentIDNameMarksCountry
1Alice85USA
2Bob92UK
3Charlie78Canada
4David95USA
5Emma88UK
6Frank65USA
7Grace90Canada

22. Table Creation & Insertion: Write two SQL queries:
a) Create the Students table as described.
b) Insert the details of a new student: StudentID=8, Name='Henry', Marks=75, Country='UK'.

23. Deletion: Write a query to delete the details of the student named ‘Frank’ from the Students table.

24. Selection & Filtering: Write two queries:
a) Select all details of all students from the Students table.
b) Select the Name and Marks of students who have scored more than 80 marks.

25. Aggregate Functions: Write a single query to find the minimum, maximum, sum, and average of the marks in the Students table.

26. GROUP BY: Write a query to find the total number of students from each country. The result should have columns Country and StudentCount.

27. ORDER BY: Write a query to display the StudentID and Marks of all students, ordered in descending order of their marks.

28. HAVING Clause: Write a query to find countries where the average marks of students are greater than 85.

29. String/Text Function: Write a query to display the names of all students in uppercase.

30. Date Function (Bonus): Assume a new AdmissionDate (DATE type) column exists. Write a query to calculate the number of days each student has been enrolled (up to today).

Leave a Reply

Your email address will not be published. Required fields are marked *