Wednesday, January 20, 2021

Python for MBA's- Multiple bar charts using Python

 

import numpy as np

import matplotlib.pyplot as plt

Agricultureproduction = [[30255020],

[40235117],

[35224519]]

X = np.arange(4)

fig = plt.figure()

ax = fig.add_axes([0,0,1,1])

ax.bar(X + 0.00, Agricultureproduction[0], color = 'b', width = 0.25)

ax.bar(X + 0.25, Agricultureproduction[1], color = 'g', width = 0.25)

ax.bar(X + 0.50, Agricultureproduction[2], color = 'r', width = 0.25)


Python for MBA's- Barplot using Python

 

import numpy as np

import matplotlib.pyplot as plt

fig=plt.figure()

ax=fig.add_axes([0,0,1,1])

GDP=[8.2,8.4,7.2,6.5,8.5,9,9.2]

Year=['2010','2011','2012','2013','2014','2015','2016']

ax.bar(Year,GDP)

plt.show()


calculating linear regression using R

 

> # calculating the impact of digital marketing campaign cost on sales
> campaign<-c(24,26,28,29)
> sales<-c(134,145,167,172)
> realtion<-lm(campaign~sales)
> print(relation)

Call:
lm(formula = x ~ y)

Coefficients:
(Intercept)            y  
    33.8312      -0.1052  

> print(summary(relation))

Call:
lm(formula = x ~ y)

Residuals:
      1       2       3       4       5 
 -9.568  23.642   3.747  -6.148 -11.674 

Coefficients:
            Estimate Std. Error t value Pr(>|t|)
(Intercept)  33.8312    16.3441   2.070    0.130
y            -0.1052     0.6855  -0.154    0.888

Residual standard error: 16.72 on 3 degrees of freedom
Multiple R-squared:  0.007795,	Adjusted R-squared:  -0.3229 
F-statistic: 0.02357 on 1 and 3 DF,  p-value: 0.8877