Codes
Codes
df = pd.DataFrame(data)
print("\nDetails:")
print(f"Row Labels: {row_labels}")
print(f"Column Labels: {column_labels}")
print("Data Types:")
print(data_types)
print(f"Dimensions: {dimensions}")
P2). Build a DataFrame to record student attendance with Student_ID, Date,
Status, and Remarks. After creating it, show the row labels, column labels,
and the data types of each column.
attendance_df = pd.DataFrame(attendance_data)
print("\nDetails:")
print(f"Row Labels: {row_labels}")
print(f"Column Labels: {column_labels}")
print("Data Types:")
print(data_types)
P3). Create a CSV file named student_results.csv containing columns
Student_ID, Name, Subject, Marks, and Grade. Populate the file with at
least five records. Write a Python script to read this CSV file and display
its contents.
Code import pandas as pd
# Create a DataFrame
df = pd.DataFrame(data)
# Create a DataFrame
df = pd.DataFrame(data)
# Create a DataFrame
df = pd.DataFrame(data)
# Create a DataFrame
df = pd.DataFrame(data)
# Create a DataFrame
df = pd.DataFrame(data)
# Create a DataFrame
df = pd.DataFrame(data)
# Create a DataFrame
df = pd.DataFrame(data)
plt.scatter(fluctuations["Day"], fluctuations["Temperature"],
color='r', label="Significant Fluctuation", zorder=5)
# Add titles and labels
plt.title("Daily Temperature Trends Over a Month", fontsize=16)
# Create a DataFrame
df = pd.DataFrame(data)
# Initial inventory
inventory = [
{"Product Name": "Laptop", "Product ID": 101, "Quantity":
10, "Price": 700},
{"Product Name": "Phone", "Product ID": 102, "Quantity":
20, "Price": 300},
{"Product Name": "Tablet", "Product ID": 103, "Quantity":
15, "Price": 400},
]
# Main program
while True:
print("\n--- Inventory Management Menu ---")
print("1. View Inventory")
print("2. Add Product")
print("3. Calculate Total Inventory Value")
print("4. Exit")
if choice == "1":
display_inventory()
elif choice == "2":
add_product()
elif choice == "3":
total_value = calculate_total_value() print(f"\nTotal
Inventory Value: ${total_value:.2f}") elif choice ==
"4":
print("Exiting Inventory Management System. Goodbye!")
break
else:
print("Invalid choice! Please try again.")
P12). Write a program to manage a grocery list using a dictionary. Each item
should have a name, quantity, and price. Tasks: 1). Allow the user to add
items to the grocery list. 2). Create a function to remove items from the list.
3). Calculate and display the total cost of all items in the grocery list
def calculate_total_cost():
total_cost = sum(item["quantity"] * item["price"] for
item in grocery_list.values())
return total_cost
# Main program
while True:
print("\n--- Grocery List Menu ---")
print("1. View Grocery List")
print("2. Add Item")
print("3. Remove Item")
print("4. Calculate Total Cost")
print("5. Exit")
choice = input("Enter your choice: ")
if choice == "1":
display_grocery_list()
elif choice == "2":
add_item()
elif choice == "3":
remove_item()
elif choice == "4":
total_cost = calculate_total_cost()
print(f"\nTotal Cost of Grocery List:
${total_cost:.2f}")
elif choice == "5":
print("Exiting Grocery List Management. Goodbye!")
break
else:
print("Invalid choice! Please try again.")
P13). Write a program that prompts the user to enter information about their
favorite books (e.g., Title, Author, Genre, Year Published). Tasks: 1). Collect
the data and write it to a new CSV file named favorite_books.csv. 2).
Display a message confirming that the data has been saved
# Main program
if __name__ == "__main__":
while True:
book_data = collect_book_data()
save_to_csv(book_data)
print(f"\nThe book '{book_data['Title']}' has been
saved to '{csv_file}' successfully!")
import pandas as pd
import matplotlib.pyplot as plt
plt.show()
P15). Histogram of Exam Scores: You have a CSV file containing students’ exam
scores. Tasks: 1). Write a program to read the CSV file. 2). Create a
histogram to visualize the distribution of scores. 3). Label the axes and
provide a title for the histogram.
import pandas as pd
import matplotlib.pyplot as plt
Code
# 2. Create a histogram
plt.hist(data['score'], bins=10, edgecolor='black')
plt.show()
P16). Create a DataFrame to represent the sales data of different products in
various regions. Include columns for Product_ID, Product_Name, Region,
Sales_Quantity, and Sales_Amount. Display the row labels, column labels,
data types of each column, and the dimensions of the DataFrame
import pandas as pd
Code
# Sample data
data = {'Product_ID': [101, 102, 103, 104, 105],
'Product_Name': ['Laptop', 'Smartphone', 'Tablet',
'Headphones', 'Smartwatch'],
'Region': ['East', 'West', 'South', 'North', 'Central'],
'Sales_Quantity': [100, 150, 80, 200, 120],
'Sales_Amount': [10000, 15000, 8000, 20000, 12000]}
# Create a DataFrame df
= pd.DataFrame(data)
print(total_sales)
P18). Using a dataset of customer purchase data, create a line graph to visualize
the trend of sales over time. Write a Python script to generate the plot and
label the axes appropriately
import pandas as pd
Code import matplotlib.pyplot as plt
plt.grid(True)
plt.show()
P19). Using a dataset of customer purchase data, create a Bar Graph to visualize
the relationship between customer age and purchase amount. Write a
Python script to generate the Bar Graph and label the axes appropriately
import pandas as pd
Code import matplotlib.pyplot as plt
plt.show()
P20). Using a dataset of customer satisfaction ratings, create a histogram
to visualize the distribution of ratings. Write a brief interpretation of
the histogram.
import pandas as pd
Code import matplotlib.pyplot as plt
# Create a histogram
plt.hist(df['Rating'], bins=5, edgecolor='black')
plt.show()
P21). Create a table Students with columns Student_ID, Name, and Marks.
Calculate the average marks of students and retrieve students
scoring above average.
FROM
Customers C
JOIN Orders
O ON
C.Customer_ID = O.Customer_ID
WHERE
O.Order_Total > 100;
P23). Create a table Products with columns Product_ID, Name, Price, and
Category. Retrieve products priced between $50-$100.
FROM
Customers C
JOIN Orders
O ON
C.Customer_ID = O.Customer_ID
ORDER BY
C.Name, O.Order_Date;
P27). Employee Department* Create two tables, Employees and
Departments. Employees: - Employee_ID (Primary Key) -
Department_ID (Foreign Key) - Name – Salary
Departments: - Department_ID (Primary Key) - Department_Name -
Location Insert 5 departments and 10 employees.
Retrieve employees by department
FROM
Departments D
JOIN
Employees E
ON
D.Department_ID = E.Department_ID
ORDER BY D.Department_Name,
E.Name;
P28). Product Sales*
Create two tables, Products and Sales. Products: - Product_ID
(Primary Key) - Product_Name – Price Sales: - Sale_ID (Primary
Key) - Product_ID (Foreign Key) - Sale_Date - Quantity Insert 5
products and 10 sales. Retrieve total sales for each product.
P.Product_ID = S.Product_ID
GROUP BY P.Product_Name,
P.Price
ORDER BY
P.Product_Name;
P29). Student Courses*
Create two tables, Students and Courses. Students: - Student_ID
(Primary Key) - Name – Department
Courses: - Course_ID (Primary Key) - Course_Name - Student_ID
(Foreign Key) Insert 5 students and 10 courses. Retrieve courses enrolled
by each student.