Python and SQL Practice Questions
1. Python Pandas Questions
a. Create a DataFrame with the following data and display it.
Data: {'Name': ['Aman', 'Riya', 'Sahil', 'Tina'], 'Age': [23, 21, 22, 20], 'Score': [90, 85, 88, 92]}
b. Add a column named "Passed" with values based on Score > 80.
c. Display rows where age is greater than 21.
d. Sort the DataFrame based on Score in descending order.
2. Python Matplotlib Questions
a. Plot a pie chart for the following data:
Subjects = ['Math', 'Science', 'English', 'History']
Marks = [85, 90, 78, 88]
b. Plot a scatter plot for the following data:
X = [1, 2, 3, 4, 5]
Y = [10, 20, 25, 30, 35]
3. SQL Queries
Given the table "Books":
BookID | Title | Author | Price
1 | Python Basics | A. Kumar | 300
2 | SQL Mastery | B. Singh | 400
3 | Data Science | C. Gupta | 500
a. Create the "Books" table with appropriate datatypes.
b. Insert the given data into the table.
c. Write a query to display books with price greater than 350.
d. Write a query to update the price of the book "Python Basics" to 350.
e. Write a query to delete books with price less than 400.
4. Python File Handling
a. Write a program to create a text file "sample.txt" and write "Hello, this is a sample file" into it.
b. Append the text "This is an additional line." to the same file.
c. Read and display the contents of the file.
5. Python Data Analysis
a. Using Pandas, create a DataFrame from a CSV file and display the first 5 rows.
b. Write a program to group the DataFrame data by a specific column and display the mean of
another column.
c. Save the grouped data into a new CSV file.
---
Write and execute these programs/queries to strengthen your skills!