Practical 2 .Ipynb - Colab (1) - Copy (1)
Practical 2 .Ipynb - Colab (1) - Copy (1)
uploaded = files.upload()
import pandas as pd
import matplotlib.pyplot as plt
%matplotlib
inline import
numpy as np
cars_data = pd.read_csv('Toyota.csv')
cars_data.head(5)
cars_data.shape
(1436, 10)
cars_data.info()
<class
'pandas.core.frame.DataFrame'>
RangeIndex: 1436 entries, 0 to
1435
Data columns (total 10 columns):
# Column Non-Null Dtype
Count
0 Price 1436 non- int64
null
1 Age 1436 non- int64
null
2 KM 1436 non- int64
null
3 FuelType 1436 non- object
null
4 HP 1436 non- int64
null
5 MetColor 1436 non- int64
null
6 Automatic 1436 non- int64
null
7 CC 1436 non- int64
null
8 Doors 1436 non- int64
null
9 Weight 1436 non- int64
null
dtypes: int64(9),
object(1) memory usage:
112.3+ KB
cars_data.isnull().values.any()
False
cars_data.shape
(1436, 10)
cars_data.dropna(axis=0, inplace=True)
cars_data.shape
(1436, 10)
plt.scatter(cars_data['Age'],cars_data['Price'],
c='green') plt.title('Scatter plot of Price vs Age of
the cars')
plt.xlabel('Age(months)'
)
plt.ylabel('Price(Euros)
') plt.show()
plt.hist(cars_data['KM'])
s() FuelType
Petrol 1264
Diesel 155
CNG 17
Name: count, dtype: int64
cars_data['Doors'].value_counts()
Door
s 67
5 4
3 62
2
4 13
8
2 2
Name: count, dtype: int64
counts=[674,622,138,
2] Doors=(5,3,4,2)
index=np.arange(len(Doors))
'Diesel','CNG')
index = np.arange(len(fuelType))
index
array([0, 1, 2])
plt.bar(index, counts, color= ['red','blue','cyan'])# index= fuel type, count = height of the bars
cars_data['Doors'].nuniqu
e() 4
sns.set(style='darkgrid')
sns.regplot(x=cars_data['Age'],y=cars_data['Price'],fit_reg=True)
sns.regplot(x=cars_data['Age'],y=cars_data['Price'],fit_reg=False)
<Axes: xlabel='Age', ylabel='Price'>
sns.regplot(x=cars_data['Age'],y=cars_data['Price'],marker='*',fit_reg=False)
sns.lmplot(x='Age',y='Price',data=cars_data,fit_reg=True,hue='FuelType',legend=True,palette="Set2")
<seaborn.axisgrid.FacetGrid at 0x7ace3d82f850>
sns.distplot(cars_data['Age'],kde=False)
<ipython-input-29-0f8bc2d269a0>:1: UserWarning:
sns.distplot(cars_data['Age'],kde=False)
<Axes: xlabel='Age'>
sns.distplot(cars_data['Age'])
<ipython-input-30-67ef1d320a1e>:1: UserWarning:
sns.distplot(cars_data['Age'])
<Axes: xlabel='Age', ylabel='Density'>
sns.distplot(cars_data['Age'],kde=False,bins=5)
<ipython-input-31-8d160a8673c0>:1: UserWarning:
sns.distplot(cars_data['Age'],kde=False,bins=5)
<Axes: xlabel='Age'>
sns.countplot(x='FuelType',data=cars_data)
sns.countplot(x='FuelType',data=cars_data,hue="Automatic")
pd.crosstab(index=cars_data['Automatic'],columns=cars_data['FuelType'],dropna=True)
Automatic
0 16 155 1185
1 1 0 79