Scatter units vs shillings and overlay the OLS line.
Goal
Show the plot and print slope.
import pandas as pd
import statsmodels.api as sm
df = pd.DataFrame({'units': [12, 9, 3, 7, 11], 'shillings': [126.0, 198.0, 93.0, 73.5, 242.0]})
fit = sm.OLS(df['shillings'], sm.add_constant(df['units'])).fit()
plt.scatter(df['units'], df['shillings'])
xs = np.linspace(df['units'].min(), df['units'].max(), 20)
plt.plot(xs, fit.params.iloc[0] + fit.params.iloc[1] * xs)
plt.xlabel('units')
plt.ylabel('shillings')
plt.show()
print(fit.params.round(3).to_dict())import pandas as pd
plt.bar(['Nairobi', 'Mombasa'], [126, 198])
plt.show()
print('ok')