Python Report Ritik
Python Report Ritik
Declaration:
I declare that this Assignment is my individual work. I have not copied it from any other student’s work or
from any other source except where due acknowledgement is made explicitly in the text, nor has any part
been written for me by any other person.
while True:
try:
num1 = float(input("Enter first number: "))
operator = input("Enter operator (+, -, *, /): ")
num2 = float(input("Enter second number: "))
if operator == "+":
result = num1 + num2
elif operator == "-":
result = num1 - num2
elif operator == "*":
result = num1 * num2
elif operator == "/":
if num2 == 0:
raise ZeroDivisionError("Cannot divide by zero")
result = num1 / num2
else:
print("Invalid operator")
continue
except ValueError:
print("Invalid input. Please enter numbers only.")
except ZeroDivisionError as e:
print(e)
II. SALES ANALYSIS
Following is the sales analysis of a data of Super Market.
1. Pie Chart: Below is an analysis on vegetables based on the data collected, determining the percentage
that each type of vegetable adds to the overall sales.
Code:
1. plt.figure(figsize=(9,9))
2. plt.pie(category_name_wise_sales['total_sales'],labels=category_name_wise_s
ales['Category Name'], autopct='%1.0f%%', colors='viridis')
3. plt.title('Pie Chart')
4. plt.show()
2.Bar Graph: Below is a bar graph analysis on vegetables based on the data collected, determining the
percentage that each type of vegetable adds to the overall sales.
Insights:
plt.figure(figsize=(20,8))
sns.barplot(x='Category
Name',y='total_sales',data=category_name_wise_sales,palette="dark")
plt.xticks(rotation=45, ha='right')
plt.xlabel('Category Name')
plt.ylabel('Total Sales')
plt.title('category_name_wise_sales')
plt.show()
III) PLACEMENT DATA ANALYSIS AND INSIGHTS
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
placement=pd.read_csv(r"c:\AASHISH\Placement_Data.csv")
data=pd.DataFrame(placement)
print(data.head(4))
print(data.columns)
print(data.shape)
print(data.info())
print(data['ssc_p'].mean())
Output: 67.30339534883721
print(data['ssc_p'].max())
Output: 89.4
print(data[data['ssc_p'] == data['ssc_p'].max()].shape[0])
Output: 1
8. Is the student who got highest Secondary Eduaction percentage, placed or not?
print(data[data['ssc_p'] == data['ssc_p'].max()]['status'].values[0])
Output: Placed
9. How many students are placed or unplaced?
print(data['status'].value_counts())
Output:
status
Placed 148
Not Placed 67
print(data['degree_t'].nunique())
Output : 3
print(data['ssc_p'].corr(data['hsc_p']))
Output: 0.5114721015997723
correlation_matrix = numeric_columns.corr()
print(correlation_matrix)
Output:
Data Pre-processing
column_to_remove = 'sl_no'
column_to_remove = 'sl_no'
data = data.drop(columns=[column_to_remove])
print(data)
print(data.isnull().sum())
Output:
gender 0
ssc_p 0
ssc_b 0
hsc_p 0
hsc_b 0
hsc_s 0
degree_p 0
degree_t 0
workex 0
etest_p 0
specialisation 0
mba_p 0
status 0
salary 67
dtype: int64
16. Fill the missing values with appropriate values and check number of null values in each column
again
data["salary"].fillna(data["salary"].mean())
17. Draw a scatter plot between 10th and 12th percentage with labels and title
plt.figure(figsize=(8, 6))
sns.scatterplot(x='ssc_p', y='hsc_p', data=data,color='b')
plt.title('Scatter Plot between 10th and 12th Percentage')
plt.xlabel('10th Percentage')
plt.ylabel('12th Percentage')
plt.show()
18. Draw the scatter plot between 10th and 12th class percentage of students grouped based on
placement data
plt.figure(figsize=(8, 6))
sns.scatterplot(x='ssc_p', y='hsc_p', hue='status', data=data)
plt.title('Scatter Plot between 10th and 12th Percentage (Grouped by Placement)')
plt.xlabel('10th Percentage')
plt.ylabel('12th Percentage')
plt.show()
19 . Draw a boxplot for 10th percentage of the students
plt.figure(figsize=(8, 6))
sns.boxplot(x='ssc_p', data=data,color='g')
plt.title('Boxplot for 10th Percentage')
plt.xlabel('10th Percentage')
plt.show()
20. Draw a boxplot for 12th percentage of the students
plt.figure(figsize=(8, 6))
sns.boxplot(x='hsc_p', data=data,color='g')
plt.title('Boxplot for 12th Percentage')
plt.xlabel('12th Percentage')
plt.show()
21. Draw a boxplot for 12th percentage of the students for placed and unplaced students
plt.figure(figsize=(10, 6))
sns.boxplot(x='status', y='hsc_p', data=data)
plt.title('Boxplot for 12th Percentage (Placed vs. Unplaced)')
plt.xlabel('Placement Status')
plt.ylabel('12th Percentage')
plt.show()
22. Draw lineplot for 10th, 12th, degree and MBA percentage
plt.figure(figsize=(15, 9))
sns.lineplot(data=data[['ssc_p', 'hsc_p', 'degree_p', 'mba_p']])
plt.title('Lineplot for 10th, 12th, Degree, and MBA Percentage')
plt.xlabel('Student')
plt.ylabel('Percentage')
plt.legend(['10th', '12th', 'Degree', 'MBA'])
plt.show()
23. Find correlation between continous columns
plt.figure(figsize=(8, 6))
sns.heatmap(correlation_continuous, annot=True, cmap='coolwarm')
plt.title('Heatmap of Correlation')
plt.show()