Professional Documents
Culture Documents
Lab 3
Lab 3
ipynb - Colaboratory
Muhammad Salman
ee171057
uploaded=files.upload()
import pandas as pd
import io
import numpy as np
import matplotlib.pyplot as plt
df = pd.read_csv(io.StringIO(uploaded['Gambiaa.csv'].decode('utf-8')))
print(df)
24
A = []
i=1
for year in df['Year'].unique():
A.append(df[(df['City']=='Banjul') & (df['Year']==year) & (df['Month']==4)]['AvgTemperature'])
#print(A)
i+=1
A= np.sum(A,axis=0)/len(df['Year'].unique())
print(A)
plt.ylim(60,80)
https://colab.research.google.com/drive/1iGI16qCbXJFqwzkw88NQJVDuUZs_PBGg#scrollTo=e5QhrYQXcNi7&printMode=true 1/4
1 /15/2020 LAB no.3.ipynb - Colaboratory
plt.scatter(Day,A)
plt.title("Gambia's April Temperature for the year 1995-2020")
plt.xlabel("Days")
plt.ylabel("Average Temperature (F)")
one=np.ones(Day.shape)
B=np.array([Day,one]).T
b=A.reshape(30,1)
bt=np.dot(B.T,B)
Binv=np.linalg.inv(bt)
Bn=np.dot(B.T,b)
xo=np.dot(Binv,Bn)
xo
array([[1.18845013e-02],
[7.69984291e+01]])
A_new=xo[0]*Day+xo[1]
plt.ylim((60,80))
plt.plot(Day,A,'o',Day,A_new)
plt.title("Gambia's April Temperature for the year 1995-2020")
plt.xlabel("Days")
plt.ylabel("Average Temperature (F)")
https://colab.research.google.com/drive/1iGI16qCbXJFqwzkw88NQJVDuUZs_PBGg#scrollTo=e5QhrYQXcNi7&printMode=true 2/4
1 /15/2020 LAB no.3.ipynb - Colaboratory
A = []
i=1
R=[]
z=0
for year in df['Year'].unique():
while i!=25:
for day in df['Day'].unique():
R=np.sum(df[(df['City']=='Banjul') & (df['Year']==year) & (df['Month']==4)& (df['Day']==i)
#R=df[(df['City']=='Banjul') & (df['Year']==year) & (df['Month']==4)& (df['Day']==i)]['Avg
z+=R
#R=0
i+=1
o=z/len(Day)
A.append(o)
z=0
print(A)
plt.plot(YEAR,A)
plt.title("Gambia's April Temperature for the year 1995-2020")
plt.xlabel("YEARs")
plt.ylabel("Average Temperature (F)")
https://colab.research.google.com/drive/1iGI16qCbXJFqwzkw88NQJVDuUZs_PBGg#scrollTo=e5QhrYQXcNi7&printMode=true 3/4
1 /15/2020 LAB no.3.ipynb - Colaboratory
https://colab.research.google.com/drive/1iGI16qCbXJFqwzkw88NQJVDuUZs_PBGg#scrollTo=e5QhrYQXcNi7&printMode=true 4/4