AFB Merged

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 63

print("Welcome to python Programming")

print("This is first python session")


Welcome to python Programming
This is first python session
In [8]:
print("This is second cell")
This is second cell
In [12]:
# Write a program to add two nos.

num1=int(input("Enter first no."))


num2=int(input("Enter second no."))
sum=num1+num2
print(sum)
Enter first no.20
Enter second no.30
50
In [13]:
# Write a program to add two nos.

num1=float(input("Enter first no."))


num2=float(input("Enter second no."))
sum=num1+num2
print(sum)
Enter first no.23.4
Enter second no.4.5
27.9
In [14]:
# Multiple Assignments

a,b,c=10,20,30
s=a+b+c
print(s)
60

# Operator Precedence and Associativity

#a=5
b=10
#c=20

z=a+b*c

#x=a=b=c

print(z)
print(x)
---------------------------------------------------------------------------
NameError Traceback (most recent call last)
~\AppData\Local\Temp\ipykernel_37792\2437437933.py in <module>
5 #c=20
6
----> 7 z=a+b*c
8
9 #x=a=b=c

NameError: name 'a' is not defined


In [3]:
# WAP to check if person is eligible to vote or not

age=int(input("Enter the age: "))


if age>=18:

print("Person is eligible to vote")


else:
print("Person is not eligible to vote")
Enter the age: 12
Person is not eligible
In [22]:
#WAP to check number is prime or not

number=int(input("Enter the number:"))


i=2
j=0
while i<number:
if number%i==0:
j=j+1
break
i=i+1
if j==0:
print(number," is prime")
else:
print(number," is not prime")
Enter the number:8
8 is not prime
In [28]:
# WAP to print 1 to 100

for x in range(1,101):
print(x,end=' ')

#print(x,' ',end=' ')


#print(x)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
In [ ]:

# WAP to swap two nos.

def swap(a,b):
temp=a
a=b
b=temp
print("Inside Function",a,b)
return a,b
x=eval(input("Enter first number: "))
y=eval(input("Enter second number: "))
x,y=swap(x,y)
print("After calling swap function: " ,x,y)
Enter first number: 4
Enter second number: 5
Inside Function 5 4
After calling swap function: 5 4
In [13]:
# Positional Arguments
# Keyword Arguments
# Parameters with default values

def display(Name="Nim" , age=25, gender="M"):


print("Name: ",Name)
print("age: ",age)
print("gender: ",gender)

display("Nimit",25,"M")
display(25,"Nimit","M")
display(Name="Nimit",age=25,gender="M")
display()
display(age=24)
Name: Nimit
age: 25
gender: M
Name: 25
age: Nimit
gender: M
Name: Nimit
age: 25
gender: M
Name: Nim
age: 25
gender: M
Name: Nim
age: 24
gender: M
In [15]:
# local and global scope of a variable
# WAP to demonstrate local and global scope of a variable

def disp():
x=5
print("x: ",x," is local variable")

x=10
disp()
print("x: ",x," is global")
x: 5 is local variable
x: 10 is global
In [34]:
# Without Recursion

def fact_fun(n):
i=1
fact=1
while(i<=n):
fact=fact*i
i=i+1
return fact
print(fact_fun(5))

120
In [35]:
# With recursion
def fact_rec(n):
if n==1:
return 1
else:
return n*fact_rec(n-1)
print(fact_rec(5))
120
In [ ]:

# List

l1=list([10,20,30])
print(l1)

l2=list(["Apple","Banana",1,56])
print(l2)

l3=list(range(0,6))
print(l3)

l4=list("xyz")
print(l4)

l4=[1,2,5,7]
l4
l3[-1]

#list slicing

l2[1:3]

# Concatenate operator(+)
l1+l2

# * operator is used to replicate elements in the list


l1*2

l5=list([10,20,30])
[10, 20, 30]
['Apple', 'Banana', 1, 56]
[0, 1, 2, 3, 4, 5]
['x', 'y', 'z']
In [24]:
# 'in' and 'is' operator
20 in l1
50 in l1

l1 is l5
Out[24]:
False
In [25]:
# del operator

del l1[0]
l1
Out[25]:
[20, 30]
In [27]:
# list comprehensions

l6=[x*10 for x in l1]


l6
Out[27]:
[200, 300]
In [29]:
# Dictionaries

# Create student table


#rollno,name,age
#MBA001,Nimit,25
#MBA002, xyz,22
#MBA003,abc,34

student={"MBA001":["Nimit",25,],
"MBA002":["xyz",22],
"MBA003":["abc",34],
"MBA001":["NG",21]
}
student
Out[29]:
{'MBA001': ['NG', 21], 'MBA002': ['xyz', 22], 'MBA003': ['abc', 34]}
In [31]:
# Add: MBA004,dak,23
student["MBA004"]=["dak",23]
student
Out[31]:
{'MBA001': ['NG', 21],
'MBA002': ['xyz', 22],
'MBA003': ['abc', 34],
'MBA004': ['dak', 23]}
In [32]:
del student["MBA002"]
student
Out[32]:
{'MBA001': ['NG', 21], 'MBA003': ['abc', 34], 'MBA004': ['dak', 23]}
In [33]:
#Traversing a dictionary

for key in student:


print(student[key])
['NG', 21]
['abc', 34]
['dak', 23]
In [35]:
# Data frames
# Create an empty data frame

import pandas

df=pandas.DataFrame()
df
Out[35]:

In [41]:
l1=[1000,"Nimit",100]
l2=[1001,"dak",80]
student=pandas.DataFrame([l1,l2],
columns=["Roll_no","Name","Marks"],
index=["R1","R2"])
student
Out[41]:
Roll_no Name Marks

R1 1000 Nimit 100

R2 1001 dak 80

In [ ]:

# WAP to remove a particular items

l1=[5,10,10,20,30,40,50,60,10]
l1.remove(40)
l1
Out[6]:
[5, 10, 10, 20, 30, 50, 60, 10]
In [8]:
l1.remove(10)
l1
Out[8]:
[5, 20, 30, 50, 60, 10]
In [9]:
l2=[20,10,10,10,450,30,50]
l2
Out[9]:
[20, 10, 10, 10, 450, 30, 50]
In [16]:
while 10 in l2:
l2.remove(10)
l2
Out[16]:
[20, 450, 30, 50]
In [21]:
import pandas as pd

l1=[1000,"Nimit",90]
l2=[1001,"xyz",80]
l3=[1003,"abc",85]
l4=[1004,"tur",70]

df=pd.DataFrame([l1,l2,l3,l4],
index=["R1","R2","R3","R4"],
columns=["Roll_No","Name","Marks%"])
df
Out[21]:
Roll_No Name Marks%

R1 1000 Nimit 90

R2 1001 xyz 80

R3 1003 abc 85

R4 1004 tur 70

In [26]:
df["Name"]["R2"]
Out[26]:
'xyz'
In [36]:
df[["Roll_No","Name"]][0:2]
Out[36]:
Roll_No Name

R1 1000 Nimit

R2 1001 xyz

In [40]:
# create data fram from dictionary

d1={"Id1":["Nimit",25,50],
"Id2":["xyz",22,60],
"Id3":["abc",34,70],

}
df=pd.DataFrame(d1).transpose()
print(df)
0 1 2
Id1 Nimit 25 50
Id2 xyz 22 60
Id3 abc 34 70
In [45]:
# Create a data frame from columns in other data frames

df1=pd.DataFrame([[1,4],[2,5],[3,6]],columns=['A','B'])
print(df1)
print(" ")

df2=pd.DataFrame([['a','d'],['b','e'],['c','f']],columns=['C','D'])
print(df2)
print(" ")

data=[df1["A"],df2["C"]]
headers=["A-df1","C-df2"]
df3=pd.concat(data,axis=1,keys=headers)
print(df3)
A B
0 1 4
1 2 5
2 3 6

C D
0 a d
1 b e
2 c f

A-df1 C-df2
0 1 a
1 2 b
2 3 c
In [51]:
ipl_df=pd.read_excel("C:/Users/91823/Downloads/IPL_Data.xlsx",sheet_name="I
PL")
ipl_df

# Create student class

class student:
Roll="MAB22264"
Name="Nimit"
Age=0
Marks=0
Grade="NULL"

student1=student()
print("Name: ",student1.Name)
print("Roll: ",student1.Roll)
print("Age: ",student1.Age)
print("Marks ",student1.Marks)
print("Grade: ",student1.Grade)

student2=student()
print("Name: ",student2.Name)
print("Roll: ",student2.Roll)
print("Age: ",student2.Age)
print("Marks ",student2.Marks)
print("Grade: ",student2.Grade)

student3=student()
print("Name: ",student3.Name)
print("Roll: ",student3.Roll)
print("Age: ",student3.Age)
print("Marks ",student3.Marks)
print("Grade: ",student3.Grade)
Name: Nimit
Roll: MAB22264
Age: 0
Marks 0
Grade: NULL
In [10]:
class student:
Roll="MAB22264"
Name="Nimit"
Age=0
Marks=0
Grade="NULL"

def display(self):
print("Name: ",self.Name)
print("Roll: ",self.Roll)
print("Age: ",self.Age)
print("Marks ",self.Marks)
print("Grade: ",self.Grade)

def calc_grade(self):
if self.Marks>80:
self.Grade="A"
elif self.Marks>=50:
self.Grade="B"
else:
self.Grade="F"
student1=student()
student1.calc_grade()
student1.display()
Name: Nimit
Roll: MAB22264
Age: 0
Marks 0
Grade: F
In [14]:
class student:
Roll="MAB22264"
Name="Nimit"
Age=0
Marks=0
Grade="NULL"

def __init__(self,R,N,A,M):
self.Roll=R
self.Name=N
self.Age=A
self.Marks=M
self.Grade=self.calc_grade()

def display(self):
print("Name: ",self.Name)
print("Roll: ",self.Roll)
print("Age: ",self.Age)
print("Marks ",self.Marks)
print("Grade: ",self.Grade)

def calc_grade(self):
if self.Marks>80:
self.Grade="A"
elif self.Marks>=50:
self.Grade="B"
else:
self.Grade="F"
return self.Grade
student1=student("MBA22264","Nimit",25,75)
student1.display()
Name: Nimit
Roll: MBA22264
Age: 25
Marks 75
Grade: B

import pandas as pd
import matplotlib.pyplot as plt
df=pd.read_excel("C:/Users/91823/Downloads/IrisData.xlsx")
plt.scatter(df["Sepal.Length"],df["Sepal.Width"])
plt.title("irisDataset")
plt.xlabel("Sepal Length")
plt.ylabel("Sepal Width")
Out[1]:
Text(0, 0.5, 'Sepal Width')
In [2]:
Year=[1920,1930,1940,1950,1960,1970,1980,1990,2000,2010]
unemployment_rate=[9.8,12,8,7.2,6.9,7,6.5,6.2,5.5,6.3]
plt.plot(Year,unemployment_rate,marker=".")
plt.title("Economy Data",fontsize=18)
plt.xlabel("Year",fontsize=14)
plt.ylabel("Unemployment Rate",fontsize=14)
Out[2]:
Text(0, 0.5, 'Unemployment Rate')
In [3]:
x_data=[1,2,3,4,5]
y_data=[5,6,7,8,4]
plt.bar(x_data,y_data)
plt.title("Bar Plot")
plt.xlabel("X-Axis")
plt.ylabel("Y-Axis")
Out[3]:
Text(0, 0.5, 'Y-Axis')
In [9]:
fruits=["Apples","Bananas","Cherries","Dates"]
quantity=[25,15,40,20]
plt.pie(quantity,labels=fruits,autopct="%0.2f%%",
explode=[0.0,0.2,0.0,0.0])
Out[9]:
([<matplotlib.patches.Wedge at 0x176d169b400>,
<matplotlib.patches.Wedge at 0x176d169bb50>,
<matplotlib.patches.Wedge at 0x176d16a42b0>,
<matplotlib.patches.Wedge at 0x176d16a49d0>],
[Text(0.7778174593052024, 0.7778174593052024, 'Apples'),
Text(-0.5901876713511441, 1.158308470393407, 'Bananas'),
Text(-0.8899186574910393, -0.6465638275138399, 'Cherries'),
Text(0.8899187482945414, -0.6465637025335375, 'Dates')],
[Text(0.4242640687119285, 0.4242640687119285, '25.00%'),
Text(-0.3631924131391656, 0.7128052125497888, '15.00%'),
Text(-0.48541017681329407, -0.3526711786439127, '40.00%'),
Text(0.4854102263424771, -0.3526711104728386, '20.00%')])
In [23]:
df_visit=pd.read_excel("C:/Users/91823/Downloads/Quality_Alloy.xlsx",sheet_
name="Weekly Visits")
df_fin=pd.read_excel("C:/Users/91823/Downloads/Quality_Alloy.xlsx",sheet_na
me="Financials")
#df_visit.Week
#df_fin
plt.figure(figsize=(20,6))
plt.xticks(rotation="vertical")
plt.bar(df_fin.Week,df_visit.Visits)
plt.title("Visits per Week")
plt.xlabel("Weeks")
plt.ylabel("Visits")
Out[23]:
Text(0, 0.5, 'Visits')

In [ ]:

import pandas as pd
import matplotlib.pyplot as plt

df_visit=pd.read_excel("C:/Users/91823/Downloads/Quality_Alloy.xlsx",sheet_
name="Weekly Visits")
df_fin=pd.read_excel("C:/Users/91823/Downloads/Quality_Alloy.xlsx",sheet_na
me="Financials")
#df_visit.Week
#df_fin
plt.figure(figsize=(20,6))
plt.xticks(rotation="vertical")
plt.bar(df_fin.Week,df_visit.Visits)
plt.title("Visits per Week")
plt.xlabel("Weeks")
plt.ylabel("Visits")
Out[1]:
Text(0, 0.5, 'Visits')

In [22]:
import statistics as st
Data=[[df_visit["Visits"][0:14].mean(),df_visit["Unique_Visits"][0:14].mean
(),df_fin["Revenue"][0:14].mean(),df_fin["Profit"][0:14].mean(),df_fin["Lbs
_Sold"][0:14].mean()],

[df_visit["Visits"][0:14].median(),df_visit["Unique_Visits"][0:14].median()
,df_fin["Revenue"][0:14].median(),df_fin["Profit"][0:14].median(),df_fin["L
bs_Sold"][0:14].median()],

[st.stdev(df_visit["Visits"][0:14]),st.stdev(df_visit["Unique_Visits"][0:14
]),st.stdev(df_fin["Revenue"][0:14]),st.stdev(df_fin["Profit"][0:14]),st.st
dev(df_fin["Lbs_Sold"][0:14])],

[min(df_visit["Visits"][0:14]),min(df_visit["Unique_Visits"][0:14]),min(df_
fin["Revenue"][0:14]),min(df_fin["Profit"][0:14]),min(df_fin["Lbs_Sold"][0:
14])],

[max(df_visit["Visits"][0:14]),max(df_visit["Unique_Visits"][0:14]),max(df_
fin["Revenue"][0:14]),max(df_fin["Profit"][0:14]),max(df_fin["Lbs_Sold"][0:
14])]]

index_name=["mean","median","std.dev.","minimmum","maximum"]
column_name=["Visits","Unique Visits","Revenue","Profit","Lbs.Sold"]
df_init=pd.DataFrame(Data,index=index_name,columns=column_name)
df_init
Out[22]:
Visits Unique Visits Revenue Profit Lbs.Sold

mean 1055.214286 975.928571 608250.123000 200233.407143 18736.728500

median 899.000000 845.500000 586169.664500 208913.000000 17269.696500

std.dev. 355.033298 319.597214 155930.397246 60691.553224 5427.392718

minimmum 626.000000 594.000000 274567.612000 62580.400000 8633.059000

maximum 1632.000000 1509.000000 890076.650000 275218.100000 28052.924000

import pandas as pd
import scipy.stats as st
import seaborn as sn
import matplotlib.pyplot as plt
df=pd.read_excel("C:/Users/91823/Downloads/Class_Data.xlsx")
sn.distplot(df['Weight'],label='Weight')
plt.legend()
results=st.ttest_1samp(df['Weight'],16)
print(results)

#p-value<0.05
# Reject the null hypothesis
# There is a significant difference b/w sample and population mean
C:\Users\91823\anaconda3\lib\site-packages\seaborn\distributions.py:2619: F
utureWarning: `distplot` is a deprecated function and will be removed in a
future version. Please adapt your code to use either `displot` (a figure-le
vel function with similar flexibility) or `histplot` (an axes-level functio
n for histograms).
warnings.warn(msg, FutureWarning)
Ttest_1sampResult(statistic=-6.832770081595879, pvalue=1.1767974520628334e-
07)
In [8]:
import pandas as pd
import scipy.stats as st
import seaborn as sn
import matplotlib.pyplot as plt
df=pd.read_excel("C:/Users/91823/Downloads/Class_Data.xlsx")
sn.distplot(df['Weight'][0:16],label='Male Weight')
sn.distplot(df['Weight'][16:32],label='Female Weight')
plt.legend()
results=st.ttest_ind(df['Weight'][0:16],df['Weight'][16:32])
print(results)

#p-value<0.05
# Reject the null hypothesis
# There is a significant difference b/w sample and population mean
C:\Users\91823\anaconda3\lib\site-packages\seaborn\distributions.py:2619: F
utureWarning: `distplot` is a deprecated function and will be removed in a
future version. Please adapt your code to use either `displot` (a figure-le
vel function with similar flexibility) or `histplot` (an axes-level functio
n for histograms).
warnings.warn(msg, FutureWarning)
C:\Users\91823\anaconda3\lib\site-packages\seaborn\distributions.py:2619: F
utureWarning: `distplot` is a deprecated function and will be removed in a
future version. Please adapt your code to use either `displot` (a figure-le
vel function with similar flexibility) or `histplot` (an axes-level functio
n for histograms).
warnings.warn(msg, FutureWarning)
Ttest_indResult(statistic=-2.338821384818735, pvalue=0.026198051170501974)
In [9]:
import pandas as pd
import scipy.stats as st
import seaborn as sn
import matplotlib.pyplot as plt
df=pd.read_excel("C:/Users/91823/Downloads/Class_Data.xlsx")
sn.distplot(df['Weight'],label='Weight')
sn.distplot(df['PostWeight'],label='PostWeight')
plt.legend()
results=st.ttest_rel(df['Weight'],df['PostWeight'])
print(results)

#p-value<0.05
# Reject the null hypothesis
# There is a significant effect on weight
C:\Users\91823\anaconda3\lib\site-packages\seaborn\distributions.py:2619: F
utureWarning: `distplot` is a deprecated function and will be removed in a
future version. Please adapt your code to use either `displot` (a figure-le
vel function with similar flexibility) or `histplot` (an axes-level functio
n for histograms).
warnings.warn(msg, FutureWarning)
C:\Users\91823\anaconda3\lib\site-packages\seaborn\distributions.py:2619: F
utureWarning: `distplot` is a deprecated function and will be removed in a
future version. Please adapt your code to use either `displot` (a figure-le
vel function with similar flexibility) or `histplot` (an axes-level functio
n for histograms).
warnings.warn(msg, FutureWarning)
Ttest_relResult(statistic=-5.085886553809134, pvalue=1.6790606940438673e-05
)
In [10]:
import pandas as pd
import scipy.stats as st
import seaborn as sn
import matplotlib.pyplot as plt
df=pd.read_excel("C:/Users/91823/Downloads/Club_Data.xlsx")
sn.distplot(df['Ydistance'][0:5],label='Club1')
sn.distplot(df['Ydistance'][5:10],label='Club2')
sn.distplot(df['Ydistance'][10:15],label='Club3')
plt.legend()
print(st.f_oneway(df['Ydistance'][0:5],df['Ydistance'][5:10],df['Ydistance'
][10:15]))
C:\Users\91823\anaconda3\lib\site-packages\seaborn\distributions.py:2619: F
utureWarning: `distplot` is a deprecated function and will be removed in a
future version. Please adapt your code to use either `displot` (a figure-le
vel function with similar flexibility) or `histplot` (an axes-level functio
n for histograms).
warnings.warn(msg, FutureWarning)
C:\Users\91823\anaconda3\lib\site-packages\seaborn\distributions.py:2619: F
utureWarning: `distplot` is a deprecated function and will be removed in a
future version. Please adapt your code to use either `displot` (a figure-le
vel function with similar flexibility) or `histplot` (an axes-level functio
n for histograms).
warnings.warn(msg, FutureWarning)
C:\Users\91823\anaconda3\lib\site-packages\seaborn\distributions.py:2619: F
utureWarning: `distplot` is a deprecated function and will be removed in a
future version. Please adapt your code to use either `displot` (a figure-le
vel function with similar flexibility) or `histplot` (an axes-level functio
n for histograms).
warnings.warn(msg, FutureWarning)
F_onewayResult(statistic=25.2754555198285, pvalue=4.9852350460386985e-05)
In [11]:
import pandas as pd
import scipy.stats as st
import seaborn as sn
import matplotlib.pyplot as plt
df=pd.read_excel("C:/Users/91823/Downloads/Club_Data.xlsx")
sn.distplot(df['Yrevenue'][0:5],label='Club1')
sn.distplot(df['Yrevenue'][5:10],label='Club2')
sn.distplot(df['Yrevenue'][10:15],label='Club3')
plt.legend()
print(st.f_oneway(df['Yrevenue'][0:5],df['Yrevenue'][5:10],df['Yrevenue'][1
0:15]))
C:\Users\91823\anaconda3\lib\site-packages\seaborn\distributions.py:2619: F
utureWarning: `distplot` is a deprecated function and will be removed in a
future version. Please adapt your code to use either `displot` (a figure-le
vel function with similar flexibility) or `histplot` (an axes-level functio
n for histograms).
warnings.warn(msg, FutureWarning)
C:\Users\91823\anaconda3\lib\site-packages\seaborn\distributions.py:2619: F
utureWarning: `distplot` is a deprecated function and will be removed in a
future version. Please adapt your code to use either `displot` (a figure-le
vel function with similar flexibility) or `histplot` (an axes-level functio
n for histograms).
warnings.warn(msg, FutureWarning)
C:\Users\91823\anaconda3\lib\site-packages\seaborn\distributions.py:2619: F
utureWarning: `distplot` is a deprecated function and will be removed in a
future version. Please adapt your code to use either `displot` (a figure-le
vel function with similar flexibility) or `histplot` (an axes-level functio
n for histograms).
warnings.warn(msg, FutureWarning)
F_onewayResult(statistic=0.010813709281022387, pvalue=0.9892541770529178)
import pandas as pd
import statsmodels.api as sm

df=pd.read_excel("C:/Users/91823/Downloads/Regression_Data.xlsx",sheet_name
="Student")
x=df[["NoOfHours","Skill"]]
x=sm.add_constant(x)
y=df[["Freshmen_Score"]]
results=sm.OLS(y,x).fit()
print(results.summary())

x
OLS Regression Results
===========================================================================
===
Dep. Variable: Freshmen_Score R-squared: 0.
918
Model: OLS Adj. R-squared: 0.
895
Method: Least Squares F-statistic: 39
.21
Date: Fri, 03 Feb 2023 Prob (F-statistic): 0.000
157
Time: 11:38:50 Log-Likelihood: -25.
062
No. Observations: 10 AIC: 56
.12
Df Residuals: 7 BIC: 57
.03
Df Model: 2
Covariance Type: nonrobust
===========================================================================
===
coef std err t P>|t| [0.025 0.9
75]
---------------------------------------------------------------------------
---
const 56.5860 15.029 3.765 0.007 21.047 92.
125
NoOfHours 6.3242 1.051 6.018 0.001 3.839 8.
809
Skill -0.1260 0.158 -0.797 0.452 -0.500 0.
248
===========================================================================
===
Omnibus: 0.753 Durbin-Watson: 1.
687
Prob(Omnibus): 0.686 Jarque-Bera (JB): 0.
444
Skew: 0.459 Prob(JB): 0.
801
Kurtosis: 2.526 Cond. No. 9
97.
===========================================================================
===

Notes:
[1] Standard Errors assume that the covariance matrix of the errors is corr
ectly specified.
C:\Users\91823\anaconda3\lib\site-packages\scipy\stats\_stats_py.py:1769: U
serWarning: kurtosistest only valid for n>=20 ... continuing anyway, n=10
warnings.warn("kurtosistest only valid for n>=20 ... continuing "
Out[12]:
const NoOfHours Skill

0 1.0 2.0 87

1 1.0 2.5 84

2 1.0 3.0 82

3 1.0 3.5 74

4 1.0 4.0 73

5 1.0 4.5 69

6 1.0 5.0 68
const NoOfHours Skill

7 1.0 5.5 55

8 1.0 6.0 63

9 1.0 6.5 80

In [13]:
import pandas as pd
import statsmodels.api as sm

df=pd.read_excel("C:/Users/91823/Downloads/Regression_Data.xlsx",sheet_name
="Sales")
x=df[["Price","Advertising"]]
x=sm.add_constant(x)
y=df[["Sales"]]
results=sm.OLS(y,x).fit()
print(results.summary())

x
OLS Regression Results
===========================================================================
===
Dep. Variable: Sales R-squared: 0.
521
Model: OLS Adj. R-squared: 0.
442
Method: Least Squares F-statistic: 6.
539
Date: Fri, 03 Feb 2023 Prob (F-statistic): 0.0
120
Time: 11:39:36 Log-Likelihood: -77.
510
No. Observations: 15 AIC: 16
1.0
Df Residuals: 12 BIC: 16
3.1
Df Model: 2
Covariance Type: nonrobust
===========================================================================
====
coef std err t P>|t| [0.025 0.
975]
---------------------------------------------------------------------------
----
const 306.5262 114.254 2.683 0.020 57.588 555
.464
Price -24.9751 10.832 -2.306 0.040 -48.576 -1
.374
Advertising 74.1310 25.967 2.855 0.014 17.553 130
.709
===========================================================================
===
Omnibus: 1.505 Durbin-Watson: 1.
683
Prob(Omnibus): 0.471 Jarque-Bera (JB): 0.
937
Skew: 0.595 Prob(JB): 0.
626
Kurtosis: 2.709 Cond. No. 7
2.2
===========================================================================
===

Notes:
[1] Standard Errors assume that the covariance matrix of the errors is corr
ectly specified.
C:\Users\91823\anaconda3\lib\site-packages\scipy\stats\_stats_py.py:1769: U
serWarning: kurtosistest only valid for n>=20 ... continuing anyway, n=15
warnings.warn("kurtosistest only valid for n>=20 ... continuing "
Out[13]:
const Price Advertising

0 1.0 5.5 3.3

1 1.0 7.5 3.3

2 1.0 8.0 3.0

3 1.0 8.0 4.5

4 1.0 6.8 3.0

5 1.0 7.5 4.0

6 1.0 4.5 3.0

7 1.0 6.4 3.7

8 1.0 7.0 3.5

9 1.0 5.0 4.0

10 1.0 7.2 3.5

11 1.0 7.9 3.2


const Price Advertising

12 1.0 5.9 4.0

13 1.0 5.0 3.5

14 1.0 7.0 2.7


AFB
Assignment-1
Submitted By: Group 7
S.NO Name Roll NO.
1 SRIJAN SINGH MBA22084
2 SURBHI KUMARI MBA22085
3 ADITYA ABHISHEK MBA22006
4 KHUSHAR NANDWANI MBA22039
5 NIMIT GUPTA MBA22264
6 HARSH KUMAR JAIN MBA22031
----------------------------------------------------------------------------------------------------------------
1. Write a program to read the marks of 5 subjects through the keyboard. Find out the
aggregate and percentage obtained by the student. Assume maximum marks that can
be obtained by a student in each subject as 100.
Code:
sub1=eval(input("Enter marks in 1st subject: "))
sub2=eval(input("Enter marks in 2nd subject: "))
sub3=eval(input("Enter marks in 3rd subject: "))
sub4=eval(input("Enter marks in 4th subject: "))
sub5=eval(input("Enter marks in 5th subject: "))
print("Aggregate marks obtained: ",sub1+sub2+sub3+sub4+sub5)
print("%age marks : ",(sub1+sub2+sub3+sub4+sub5)/5,"%")
Output:

1|Page
2. Write a program to read a four-digit number through the keyboard and calculate the
sum of its digits.
Code:
num=int(input("Enter a 4 digit number: "))
result=0
while(num>0):
result=result+ num%10
num=num//10
print("Sum of digits: ",result)

Output:

3. Write a program to read the distance between any two cities in kilometer(km) and
print the distances in meters(m), centimeter(cm) and miles.
Note: 1 km = 1000 meter
1 km = 100000 centimeter
1 km = 0.6213 miles
Code:
distance=eval(input("Enter distance b/w two citites in km: "))
print("Distance in meters(m): ",distance*1000,"m")
print("Distance in centimeters(cm): ",distance*100000,"cm")
print("Distance in miles: ",distance*.6213,"miles")
Output:

2|Page
4. Write a program to read the weight of an object in kilogram and print its weight in
pound and ton.
Note: 1 kg = 2.20 pound
1 kg = 0.001 tonne
Code:
weight=eval(input("Enter weight in kg: "))
print("Weight in pounds: ",weight*2.2,"pound")
print("Weight in ton: ",weight*.001,"ton")
Output:

5. Read a distance in meters and a time in seconds through the keyboard. Write a
program to calculate the speed of a car in meter/second.
Note: Speed = Distance/Time
Code:
distance=eval(input("Enter distance in meters: "))
time=eval(input("Enter time in seconds: "))
print("Speed: ",distance/time,"m/s")
Output:

6. Write a program to read the radius of a sphere from the user and calculate the
volume
of the sphere.
Note: Volume of sphere = 4/3*3.14*r3
Code:
radius=eval(input("Enter radius of a sphere: "))

3|Page
print("Volume of sphere: ",4/3*3.14*radius**3)
Output:

7. An ATM contains Indian currency notes of 100, 500 and 1000. To withdraw cash
from this ATM, the user has to enter the number of notes he/she wants of each
currency, i.e., of 100, 500, and 1000. Write a program to calculate the total amount
withdrawn by the person from the ATM in rupees.
Code:
hundred_notes=int(input("Enter number of hundred rupees notes: "))
fivehundred_notes=int(input("Enter number of Five hundred rupees notes: "))
thousand_notes=int(input("Enter number of thousand rupees notes: "))
print("Total amount withdrawn from ATM:
",hundred_notes*100+fivehundred_notes*500+thousand_notes*1000)
Output:

8. Write a program to prompt (input) year and check if it is a leap year.


Code:
def checkYear(a):
if (a % 4) == 0:
if (a % 100) == 0:
if (a % 400) == 0:
return True
else:
return False
else:

4|Page
return True
else:
return False

year=int(input("Enter the year: "))


if(checkYear(year)):
print("Leap Year")
else:
print("Not a Leap Year")
Output:

9. Write a program to calculate an Internet browsing bill. Use the conditions specified
as
follows:
a. 1 Hour - ₹20
b. 1⁄2 Hour - ₹10
c. Unlimited hours in a day - ₹100
The owner should enter the number of hours spent on browsing.
Code:
hours=int(input("Enter the number of hours spent browsing: "))
minutes=int(input("Enter extra minutes spent browsing: "))

if(hours<6):
print("Browsing Bill: Rs",hours*20+minutes/30*10)
else:
print("Browsing Bill: Rs 100")

5|Page
Output:

10. Write a nested if statements to print the appropriate message depending on the
value of the variables temperature and humidity as given as follows. Assume that the
temperature can only be warm and cold and the humidity can only be dry and humid.

Code:
temp=input("Enter temperature: ")
humidity=input("Enter humidity: ")
if(temp == 'warm'):
if(humidity == 'dry'):
print("Play Basketball")
else:
print("Play Tennis")
else:
if(humidity == 'dry'):
print("Play Cricket")
else:
print("Swim")
Output:

6|Page
11. Write a program to calculate the square of only those numbers whose least
significant
digit is 5.
Example: Enter the number: 25
Square: 25*25 = 625
Code:
num=int(input("Enter the number: "))
if(num%10==5):
print("Square: ",num%10**2)
else:
print("Invald number.")
Output:

12. Write a program that asks for input n and prints sequence of powers of 5 from 50 to
5n in separate lines.
Note: The input number n should be positive.
Example:
Input: N=4
Output:
1
5
25
125
625
Code:
num=int(input("Enter the number: "))
value=range(num)
for i in value:
print(5**i)

7|Page
Output:

13. Write a program to display the numbers of a series 1, 4, 9, 16, 25, ..., n by using for
loop.
Code:
num=int(input("Enter the number: "))
i=1
while(i<=num):
print(i**2)
i=i+1
Output:

14. Write a program using the while loop, which prints the sum of every fifth number
from 0 to 500 (including both 0 and 500).
Code:
result=0
while(i<=500):
if(i%5==0):
result=result+i
i=i+1
print("Sum: ",result)

8|Page
Output:

15. Write a program using the while loop to read the positive integer and count the
number of decimal digits in a positive integer.
Code:
count=0
num=int(input("Enter the number: "))
while(num>0):
count=count+1
num=num//10
print("Number of digits: ",count)
Output:

16. Write programs for the following series using the while loop.
a. x+x2/!2+ x3/!3+...n
Code:
def fact(n):
if n == 1:
return 1
else:
return n * fact(n - 1)

def sum(x, n):


total =0

for i in range (1, n + 1, 1):

9|Page
total = total + (pow(x, i) / fact(i + 1))

return total

x=int(input("Enter value of x: "))


n=int(input("Enter value of n: "))

print ("Sum is: ",(sum(x, n)))


Output:

b. 1+x+x2+x3+...xn
Code:
i=0
n=int(input("Enter value of n: "))
while(i<=n):
print(n**i)
i=i+1
Output:

10 | P a g e
Analytics for Business

Group Assignment -2

Submitted By
Group 7
S.NO Name Roll NO.

1 SRIJAN SINGH MBA22084

2 SURBHI KUMARI MBA22085

3 ADITYA ABHISHEK MBA22006

4 KHUSHAR NANDWANI MBA22039

5 NIMIT GUPTA MBA22264

6 HARSH KUMAR JAIN MBA22031

1|Page
1. Write a function Eval_Quadratic_Equa(a, b, c, x) which returns the value of any
quadratic equation of form ax2+bx+c
Code:
def Eval_Quadratic_Equa(a,b,c,x):
return a*x**2+b*x+c
Eval_Quadratic_Equa(3,4,2,1)
Output:

2. Write a function calc_exp(base, exp) which computes the exponent of any number,
i.e., baseexp. The function should take two values as base, which can be float or
integer. Exp will be an integer greater than 0.
Code:
def calc_exp(base,exp):
return base**exp
calc_exp(6,8)
Output:

3. Write a function Calc_GCD_Recurr(a, b) which calculates the greater common


divisor (GCD) of two number. The function should take two positive integers and
should return one integer as GCD.
Code:
def Calc_GCD_Recurr(a,b):
i=1
gcd=1
if(a<b):
while(i<=a):
if(a%i==0 and b%i==0):

2|Page
gcd=i
i=i+1
else:
while(i<=b):
if(a%i==0 and b%i==0):
gcd=i
i=i+1
return gcd
print("GCD =",Calc_GCD_Recurr(24,16))
Output:

4. Write a function reverse_number() to return the reverse of the number entered.


Code:
def reverse_number(num):
num_as_str=str(num)
i=len(num_as_str)-1
result=""
while(i>=0):
result=result+num_as_str[i]
i=i-1
return int(result)
reverse_number(9608741)
Output:

3|Page
5. A four-digit integer is entered through the keyword. Write a function to calculate the
sum of the four-digit number.
Code:
def cal_sum(num):
result=0
while(num>0):
result=result+ num%10
num=num//10
return result
a=int(input("Enter four digit number: "))
print("Sum is:",cal_sum(a))
Output:

6. Write a program to create a class circle. Perform the following operations on it.
a) Define the attribute radius.
b) Define the method named get_radius() which returns the radius of the circle.
c) Define the method named calc_area() which returns the area of circle.
d) Use constructor (__init__ method) to initialize the attributes.
Code:
class circle:
radius=6
def __init__(self,r):
self.radius=r
def get_radius(self):
print("Radius: ",self.radius)
def calc_area(self):
print("Area of circle: ",3.14*self.radius**2)
ob1=circle(17)

4|Page
ob1.get_radius()
ob1.calc_area()
Output:

7. Create below data frame.

Code:
import pandas as pd

l1=["Tom","Reacher",25]
l2=["Krish","Pete",30]
l3=["Nick","Wilson",26]
l4=["Juli","Williams",22]

df=pd.DataFrame([l1,l2,l3,l4],
index=["0","1","2","3"],
columns=["FName","LName","Age"])
Output:

5|Page
8. Create below student data frame and do the below exercise.
ID Name Gender Age Family_Income
MBA21001 Rohit Male 24 1,20,000
MBA21002 Meenal Female 25 98,000
MBA21003 Sneha Female 22 1,12,000
MBA21004 Mrigank Male 23 85,000
MBA21005 Naresh Male 25 92,000
MBA21006 Deepika Female 23 1,06,000

a) Calculate mean, median, maximum, minimum, and standard deviation of salary.


b) Calculate mean, median, maximum, minimum, and standard deviation of age.
c) Is there any correlation between age and salary?
Code:
import statistics
import numpy as np

l1=["MBA21001","Rohit","Male",24,120000]
l2=["MBA21002","Meenal","Female",25,98000]
l3=["MBA21003","Sneha","Female",22,112000]
l4=["MBA21004","Mrigank","Male",23,85000]
l5=["MBA21005","Naresh","Male",25,92000]
l6=["MBA21006","Deepika","Female",23,106000]

df=pd.DataFrame([l1,l2,l3,l4,l5,l6],
columns=["ID","Name","Gender","Age","Family_Income"])
print(df)
print("Mean salary: ",statistics.mean(df.Family_Income))
print("Median salary: ",statistics.median(df.Family_Income))
print("Maximum salary: ",max(df.Family_Income))
print("Minimum salary: ",min(df.Family_Income))
print("SD of salary: ",statistics.stdev(df.Family_Income))
print("Mean Age: ",statistics.mean(df.Age))
print("Median Age: ",statistics.median(df.Age))

6|Page
print("Maximum Age: ",max(df.Age))
print("Minimum Age: ",min(df.Age))
print("SD of Age: ",statistics.stdev(df.Age))
print("Correlation b/w salary and age: ",np.corrcoef(df.Family_Income,df.Age))

Output:

9. Draw line and bar diagram on below data.

7|Page
Code:
import matplotlib.pyplot as plt

Month=['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec']
Sales=[50,30,20,15,17,55,40,25,20,60,35,40]
plt.plot(Month,Sales,marker=".")
plt.title("Sales Data",fontsize=20)
plt.xlabel("Month",fontsize=16)
plt.ylabel("Sales",fontsize=16)
Output:

Code:
Month=['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec']
Sales=[50,30,20,15,17,55,40,25,20,60,35,40]

8|Page
plt.bar(Month,Sales)
plt.title("Bar Plot")
plt.xlabel("X-Axis")
plt.ylabel("Y-Axis")
Output:

10. Draw a pie chart to visualize the placement statistics on below placement data:

9|Page
Code:
Industry=["IT","Sales & Marketing","Finance & Banking","Manufacturing","Others"]
Placement=[55,88,39,24,63]
plt.pie(Placement,labels=Industry,autopct="%0.2f%%", explode=[0.2,0.2,0.0,0.0,0.0])
Output:

10 | P a g e
11. Write a program to create a class named Demo. Define two methods Get_String()
and Print_String(). Accept the string from user and print the string in upper case.
Code:
class Demo:
str="HI"
def Get_String(self):
self.str=input("Enter string: ")
def Print_String(self):
print(self.str)
ob=Demo()
ob.Get_String()
ob.Print_String()
Output:

12. Write a program to create a class Circle. Perform the following operations on it.
a. Define the attribute radius.
b. Define the constructor with one argument containing radius.
c. Define the method named get_radius() which returns the area of the circle.
d. Define the method named calc_area() which returns the area of the circle.
Code:
class circle:
radius=6

def __init__(self,r):
self.radius=r
def get_radius(self):
print("Radius: ",self.radius)
def calc_area(self):

11 | P a g e
print("Area of circle: ",3.14*self.radius**2)
ob1=circle(22)
ob1.get_radius()
ob1.calc_area()

Output:

13. Write a program to create the class Point. Perform the following operations on it.
a. Initialize X and Y coordinates of the point.
b. Print the coordinates by defining the method Display.
c. Define the method Translate(x, y) to move the point X units in X direction and Y
units in Y direction.
Code:
class Point:
x_coordinate=7
y_coordinate=4

def display(self):
print("X-coordinate = ",self.x_coordinate)
print("Y-coordinate = ",self.y_coordinate)

def Translate(self,x,y):
self.x_coordinate=self.x_coordinate+x
self.y_coordinate=self.y_coordinate+y
self.display()

obj=Point()
obj.display()
obj.Translate(6,9)

12 | P a g e
Output:

13 | P a g e
AFB
Assignment-3
Submitted By: Group 7
S.NO Name Roll NO.
1 SRIJAN SINGH MBA22084
2 SURBHI KUMARI MBA22085
3 ADITYA ABHISHEK MBA22006
4 KHUSHAR NANDWANI MBA22039
5 NIMIT GUPTA MBA22264
6 HARSH KUMAR JAIN MBA22031
----------------------------------------------------------------------------------------------------------------
1. Using data in the Weekly Visits and Financials worksheets, create four column
charts (like Figure 1: Visits to the QA Website per Week) for unique visits over
time, revenue over time, profit over time, and pounds sold over time.
a) Vists over Time
Code:
import pandas as pd
import matplotlib.pyplot as plt

df_visit=pd.read_excel("C:/Users/91823/Downloads/Quality_Alloy.xlsx",sheet_name
="Weekly Visits")
df_fin=pd.read_excel("C:/Users/91823/Downloads/Quality_Alloy.xlsx",sheet_name=
"Financials")
plt.figure(figsize=(20,6))
plt.xticks(rotation="vertical")
plt.bar(df_fin.Week,df_visit.Visits)
plt.title("Visits per Week")
plt.xlabel("Weeks")
plt.ylabel("Visits")

Output

1|Page
b) Revenue over Time
Code:
import pandas as pd
import matplotlib.pyplot as plt

df_visit=pd.read_excel("C:/Users/91823/Downloads/Quality_Alloy.xlsx",sheet_n
ame="Weekly Visits")
df_fin=pd.read_excel("C:/Users/91823/Downloads/Quality_Alloy.xlsx",sheet_na
me="Financials")
plt.figure(figsize=(20,6))
plt.xticks(rotation="vertical")
plt.bar(df_fin.Week,df_fin.Revenue)
plt.title("Revenue per Week")
plt.xlabel("Weeks")
plt.ylabel("Revenue")

Output:

c) Profit Over Time

Code:
import pandas as pd
import matplotlib.pyplot as plt

df_visit=pd.read_excel("C:/Users/91823/Downloads/Quality_Alloy.xlsx",sheet_name
="Weekly Visits")
df_fin=pd.read_excel("C:/Users/91823/Downloads/Quality_Alloy.xlsx",sheet_name=
"Financials")
plt.figure(figsize=(20,6))
plt.xticks(rotation="vertical")
plt.bar(df_fin.Week,df_fin.Profit)
plt.title("Profits per Week")
plt.xlabel("Weeks")
plt.ylabel("Profit")

2|Page
Output:

d) Lbs_Sold over Time


Code:
import pandas as pd
import matplotlib.pyplot as plt

df_visit=pd.read_excel("C:/Users/91823/Downloads/Quality_Alloy.xlsx",sheet_n
ame="Weekly Visits")
df_fin=pd.read_excel("C:/Users/91823/Downloads/Quality_Alloy.xlsx",sheet_na
me="Financials")
plt.figure(figsize=(20,6))
plt.xticks(rotation="vertical")
plt.bar(df_fin.Week,df_fin.Lbs_Sold)
plt.title("Lbs_Sold per Week")
plt.xlabel("Weeks")
plt.ylabel("Lbs_Sold")

Output:

3|Page
2. Using the same data, calculate the following summary statistics for visits, unique
visits, revenue, profit, and pounds sold: mean, median, standard deviation,
minimum, and maximum, for the initial, pre-promotion, promotion, and post-
promotion periods. So, for each period you should provide 25 values: five
summary measures for each of five variables, as per the table below for the
initial period.

Code:
import statistics as st
Data=[[df_visit["Visits"][0:14].mean(),df_visit["Unique_Visits"][0:14].mean(),df_fin
["Revenue"][0:14].mean(),df_fin["Profit"][0:14].mean(),df_fin["Lbs_Sold"][0:14].me
an()],

[df_visit["Visits"][0:14].median(),df_visit["Unique_Visits"][0:14].median(),df_fin["R
evenue"][0:14].median(),df_fin["Profit"][0:14].median(),df_fin["Lbs_Sold"][0:14].me
dian()],

[st.stdev(df_visit["Visits"][0:14]),st.stdev(df_visit["Unique_Visits"][0:14]),st.stdev(df
_fin["Revenue"][0:14]),st.stdev(df_fin["Profit"][0:14]),st.stdev(df_fin["Lbs_Sold"][0:
14])],

[min(df_visit["Visits"][0:14]),min(df_visit["Unique_Visits"][0:14]),min(df_fin["Reve
nue"][0:14]),min(df_fin["Profit"][0:14]),min(df_fin["Lbs_Sold"][0:14])],

[max(df_visit["Visits"][0:14]),max(df_visit["Unique_Visits"][0:14]),max(df_fin["Rev
enue"][0:14]),max(df_fin["Profit"][0:14]),max(df_fin["Lbs_Sold"][0:14])]]

index_name=["mean","median","std.dev.","minimmum","maximum"]
column_name=["Visits","Unique Visits","Revenue","Profit","Lbs.Sold"]

df_init=pd.DataFrame(Data,index=index_name,columns=column_name)
df_init

Output:

4|Page
b) Pre- Promotion

Code:
Data=[[df_visit["Visits"][14:35].mean(),df_visit["Unique_Visits"][14:35].mean(),df_f
in["Revenue"][14:35].mean(),df_fin["Profit"][14:35].mean(),df_fin["Lbs_Sold"][14:3
5].mean()],

[df_visit["Visits"][14:35].median(),df_visit["Unique_Visits"][14:35].median(),df_fin[
"Revenue"][14:35].median(),df_fin["Profit"][14:35].median(),df_fin["Lbs_Sold"][14:
35].median()],

[st.stdev(df_visit["Visits"][14:35]),st.stdev(df_visit["Unique_Visits"][14:35]),st.stdev
(df_fin["Revenue"][14:35]),st.stdev(df_fin["Profit"][14:35]),st.stdev(df_fin["Lbs_Sol
d"][14:35])],

[min(df_visit["Visits"][14:35]),min(df_visit["Unique_Visits"][14:35]),min(df_fin["Re
venue"][14:35]),min(df_fin["Profit"][14:35]),min(df_fin["Lbs_Sold"][14:35])],

[max(df_visit["Visits"][14:35]),max(df_visit["Unique_Visits"][14:35]),max(df_fin["R
evenue"][14:35]),max(df_fin["Profit"][14:35]),max(df_fin["Lbs_Sold"][14:35])]]

index_name=["mean","median","std.dev.","minimmum","maximum"]
column_name=["Visits","Unique Visits","Revenue","Profit","Lbs.Sold"]

df_init_pre_promotion=pd.DataFrame(Data,index=index_name,columns=column_na
me)
df_init_pre_promotion

Output:

c) Promotion

Code:
Data=[[df_visit["Visits"][35:52].mean(),df_visit["Unique_Visits"][35:52].mean(),df_f
in["Revenue"][35:52].mean(),df_fin["Profit"][35:52].mean(),df_fin["Lbs_Sold"][35:5
2].mean()],

[df_visit["Visits"][35:52].median(),df_visit["Unique_Visits"][35:52].median(),df_fin[

5|Page
"Revenue"][35:52].median(),df_fin["Profit"][35:52].median(),df_fin["Lbs_Sold"][35:
52].median()],

[st.stdev(df_visit["Visits"][35:52]),st.stdev(df_visit["Unique_Visits"][35:52]),st.stdev
(df_fin["Revenue"][35:52]),st.stdev(df_fin["Profit"][35:52]),st.stdev(df_fin["Lbs_Sol
d"][35:52])],

[min(df_visit["Visits"][35:52]),min(df_visit["Unique_Visits"][35:52]),min(df_fin["Re
venue"][35:52]),min(df_fin["Profit"][35:52]),min(df_fin["Lbs_Sold"][35:52])],

[max(df_visit["Visits"][35:52]),max(df_visit["Unique_Visits"][35:52]),max(df_fin["R
evenue"][35:52]),max(df_fin["Profit"][35:52]),max(df_fin["Lbs_Sold"][35:52])]]

index_name=["mean","median","std.dev.","minimmum","maximum"]
column_name=["Visits","Unique Visits","Revenue","Profit","Lbs.Sold"]

df_init__promotion=pd.DataFrame(Data,index=index_name,columns=column_name)
df_init__promotion

Output

d) Post-Promotion

Code:
Data=[[df_visit["Visits"][52:66].mean(),df_visit["Unique_Visits"][52:66].mean(),df_f
in["Revenue"][52:66].mean(),df_fin["Profit"][52:66].mean(),df_fin["Lbs_Sold"][52:6
6].mean()],

[df_visit["Visits"][52:66].median(),df_visit["Unique_Visits"][52:66].median(),df_fin[
"Revenue"][52:66].median(),df_fin["Profit"][52:66].median(),df_fin["Lbs_Sold"][52:
66].median()],

[st.stdev(df_visit["Visits"][52:66]),st.stdev(df_visit["Unique_Visits"][52:66]),st.stdev
(df_fin["Revenue"][52:66]),st.stdev(df_fin["Profit"][52:66]),st.stdev(df_fin["Lbs_Sol
d"][52:66])],

[min(df_visit["Visits"][52:66]),min(df_visit["Unique_Visits"][52:66]),min(df_fin["Re
venue"][52:66]),min(df_fin["Profit"][52:66]),min(df_fin["Lbs_Sold"][52:66])],

6|Page
[max(df_visit["Visits"][52:66]),max(df_visit["Unique_Visits"][52:66]),max(df_fin["R
evenue"][52:66]),max(df_fin["Profit"][52:66]),max(df_fin["Lbs_Sold"][52:66])]]

index_name=["mean","median","std.dev.","minimmum","maximum"]
column_name=["Visits","Unique Visits","Revenue","Profit","Lbs.Sold"]

df_init_pp=pd.DataFrame(Data,index=index_name,columns=column_name)
df_init_pp

Output:

3. Create a column chart of the mean visits over the four periods—that is, your
chart should have four columns, the first representing the mean visits during the
initial period, the second representing the mean visits during the pre-promotion
period, etc. Create four more such charts, this time using the mean unique visits,
mean revenue, mean profit, and mean pounds sold statistics.
Code:
Period=['Initial','Pre-Promotions','Promotions','Post-Promotions']
Visits=[df_init['Visits']['mean'],df_init_pre_promotion['Visits']['mean'],df_init__prom
otion['Visits']['mean'],df_init_pp['Visits']['mean']]
plt.bar(Period,Visits)
plt.title("Bar Plot")
plt.xlabel("Period")
plt.ylabel("Mean No. Of Visits")

7|Page
Output:

b) Unique Visits
Code:
Period=['Initial','Pre-Promotions','Promotions','Post-Promotions']
Unique_Visits=[df_init['Unique Visits']['mean'],df_init_pre_promotion['Unique
Visits']['mean'],df_init__promotion['Unique Visits']['mean'],df_init_pp['Unique
Visits']['mean']]
plt.bar(Period,Unique_Visits)
plt.title("Bar Plot")
plt.xlabel("Period")
plt.ylabel("Mean No. Of Unique Visits")

Output:

8|Page
c) Revenue
Code:
Period=['Initial','Pre-Promotions','Promotions','Post-Promotions']
Revenue=[df_init['Revenue']['mean'],df_init_pre_promotion['Revenue']['mean'],df_ini
t__promotion['Revenue']['mean'],df_init_pp['Revenue']['mean']]
plt.bar(Period,Revenue)
plt.title("Bar Plot")
plt.xlabel("Period")
plt.ylabel("Mean Revenue")

Output:

d) Profit
Code:
Period=['Initial','Pre-Promotions','Promotions','Post-Promotions']
Profit=[df_init['Profit']['mean'],df_init_pre_promotion['Profit']['mean'],df_init__prom
otion['Profit']['mean'],df_init_pp['Profit']['mean']]
plt.bar(Period,Profit)
plt.title("Bar Plot")
plt.xlabel("Period")
plt.ylabel("Mean Profit")

9|Page
Output:

e) Lbs_Sold
Code:
Period=['Initial','Pre-Promotions','Promotions','Post-Promotions']
Lbs_Sold=[df_init['Lbs.Sold']['mean'],df_init_pre_promotion['Lbs.Sold']['mean'],df_i
nit__promotion['Lbs.Sold']['mean'],df_init_pp['Lbs.Sold']['mean']]
plt.bar(Period,Lbs_Sold)
plt.title("Bar Plot")
plt.xlabel("Period")
plt.ylabel("Mean Lbs.Sold")

Output:

10 | P a g e
4. Create a scatter diagram of revenue versus pounds sold. (Revenue should be on
the y, or vertical, axis.) Determine the correlation coefficient of revenue and
pounds sold.

Code:
import pandas as pd
import matplotlib.pyplot as plt
import numpy as np
df=pd.read_excel("C:/Users/91823/Downloads/Quality_Alloy.xlsx",sheet_name="Fin
ancials")
plt.scatter(df["Lbs_Sold"],df["Revenue"])
plt.xlabel("Lbs_Sold")
plt.ylabel("Revenue")
print("Correlation b/w Revenue & Lbs_Sold",np.corrcoef(df.Lbs_Sold,df.Revenue))

Output:

5. Now create the scatter diagram of revenue versus visits. (Given your previous
work, what do you expect this plot to look like?) Determine the correlation
coefficient of revenue and visits.

Code:
df=pd.read_excel("C:/Users/91823/Downloads/Quality_Alloy.xlsx",sheet_name="We
ekly Visits")
plt.scatter(df["Visits"],df["Revenue"])
plt.xlabel("No. of Visits")
plt.ylabel("Revenue")
print("Correlation b/w Revenue & Visits",np.corrcoef(df.Visits,df.Revenue))

11 | P a g e
Output:

6. The Lbs. Sold worksheet contains the pounds of material sold per week from
January 3, 2005, through the week of July 19, 2010.
a) Determine the following summary values for this data: mean, median,
standard deviation, minimum, and maximum.
b) Create a histogram of the pounds of material sold data.

Code:
df=pd.read_excel("C:/Users/91823/Downloads/Quality_Alloy.xlsx",sheet_name="Lb
s. Sold")
print("Mean: ",df["Lbs. Sold"].mean())
print("Median: ",df["Lbs. Sold"].median())
print("Standard Deviation: ",df["Lbs. Sold"].std())
print("Maximum: ",df["Lbs. Sold"].max())
print("Minimum: ",df["Lbs. Sold"].min())
plt.hist(df["Lbs. Sold"],bins=15)

Output:

12 | P a g e
7. Determine how well this data follows the Empirical Rule by completing the
following table.

Solution:

13 | P a g e
AFB
Assignment-4
Submitted By: Group 7
S.NO Name Roll NO.
1 SRIJAN SINGH MBA22084
2 SURBHI KUMARI MBA22085
3 ADITYA ABHISHEK MBA22006
4 KHUSHAR NANDWANI MBA22039
5 NIMIT GUPTA MBA22264
6 HARSH KUMAR JAIN MBA22031
----------------------------------------------------------------------------------------------------------------

1. Is there any variable (e.g., age, gender, language spoken, work experience)
that affects how much a student can expect to make?

Code:
import pandas as pd
import statsmodels.api as sm

df=pd.read_excel("C:/Users/91823/Downloads/MBA Starting Salaries.xlsx")


df
x=df[["age","sex","frstlang","work_yrs"]]
x=sm.add_constant(x)
y=df[["salary"]]
results=sm.OLS(y,x).fit()
print(results.summary())

Output:

Only age will affect how much a student can expect to make because for other
variables p > 0.05

2. Can starting salaries be Predicted Based on Graduating Data (i.e., GPA, gender,
work experience)?

Code:
import pandas as pd
import statsmodels.api as sm

1|Page
df=pd.read_excel("C:/Users/91823/Downloads/MBA Starting Salaries.xlsx")

x=df[["s_avg","sex","work_yrs"]]
x=sm.add_constant(x)
y=df[["salary"]]
results=sm.OLS(y,x).fit()
print(results.summary())

Output:

Starting salaries cannot be Predicted Based on Graduating Data (i.e., GPA, gender,
work experience) as for all the variables p > 0.05

2|Page

You might also like