Professional Documents
Culture Documents
import pandas as pd
df=pd.read_csv("railway_gauges.csv")
print(df.head(10))
df=df.drop('Total',axis=1)
ax=df.plot(x='Year',kind="bar")
plt.xticks(rotation=80)
plt.xlabel('Year')
plt.ylabel('Total')
plt.savefig('railway_gauges.png')
plt.show()
Project2:
To represents a reviews of score in pandas module
import pandas as pd
df=pd.read_csv('ign.csv')
print(df.head(3))
print(df.shape)
print(df.iloc[:5,:])
print(df.index)
print(df.loc[:4,"platform"])
print(df.loc[:5,["score","release_year"]])
type(df["score"])
type(df["title"])
print(df["title"].head(3))
print(df["score"].mean())
print(df["score"]/3)
score_filter=df["score"]>9
filtered_df=df[score_filter]
filtered_df.head(3)
ipad_filter=(df["score"]>9)&(df["platform"]=="ipad")
filtered_df=df[ipad_filter]
filtered_df.head()
Project3:
To represents a scatter
A:
import pandas as pd
x = dataframe.Height
y = dataframe.Latitude
plt.scatter(x,y)
plt.show()
B:
import pandas as pd
x = dataframe.Height
y = dataframe.Latitude
stats = linregress(x, y)
m = stats.slope
b = stats.intercept
plt.figure(figsize=(10,10))
plt.scatter(x,y,marker='x')
plt.xlabel("Height (m)",fontsize=20)
plt.ylabel("Latitude",fontsize=20)
plt.xticks(fontsize=10)
plt.yticks(fontsize=10)
plt.savefig("python-linear-reg-custom.png")
Project4:
To represents a bedrooms in matplotlib
import numpy as np
import pandas as pd
import mpl_toolkits
dt=pd.read_csv("kc_house_data.csv")
dt.head()
dt.describe()
dt['bedrooms'].value_counts().plot(kind='bar')
plt.title('number of bedrooms')
plt.xlabel('Bedrooms')
plt.ylabel('Count')
sns.despine
plt.figure(figsize=(10,10))
sns.jointplot(x=dt.lat.values,y=dt.long.values,size=10)
plt.ylabel('Longitude',fontsize=10)
plt.xlabel('Longitude',fontsize=10)
plt.show()
sns.despine
plt.scatter(dt.price,dt.sqft_living)
plt.scatter(dt.price,dt.long)
plt.scatter(dt.bedrooms,dt.price)
plt.xlabel("bedrooms")
plt.ylabel("price")
plt.show()
sns.despine
Project5:
Test the mathematical equation (7a+3b+4c+9d) and display
output along with any graph with these equation.
from random import randint
TRAIN_SET_LIMIT=1000
TRAIN_SET_COUNT=100
TRAIN_INPUT=list()
TRAIN_OUTPUT=list()
for i in range(TRAIN_SET_COUNT):
a = randint(0,TRAIN_SET_LIMIT)
b = randint(0,TRAIN_SET_LIMIT)
c = randint(0,TRAIN_SET_LIMIT)
d = randint(0,TRAIN_SET_LIMIT)
op = (7*a)+(3*b)+(4*c)+(9*d)
TRAIN_INPUT.append([a,b,c,d])
TRAIN_OUTPUT.append(op)
predictor=LinearRegression(n_jobs=-1)
predictor.fit(X=TRAIN_INPUT,y=TRAIN_OUTPUT)
X = [[]]
for i in range(4):
n = input('enter n value:')
X.append(n)
X_TEST = [[a,b,c,d]]
outcome = predictor.predict(X_TEST)
coefficients = predictor.coef_
print('outcome{} \n coefficients{}'.format(outcome,coefficients))
plt.bar([a,b,c,d],width=50,height=100)
plt.xlabel('coefficients')
plt.ylabel('outcomes')
plt.show()