-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpandas-pylot-project.py
More file actions
88 lines (63 loc) · 2.14 KB
/
pandas-pylot-project.py
File metadata and controls
88 lines (63 loc) · 2.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# -*- coding: utf-8 -*-
"""
Created on Wed Feb 11 11:29:53 2021
@author: akshay
"""
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt
# %matplotlib inline only for jupiter notebook
sns.set(color_codes=True)
# reading csv file using pandas
car= pd.read_csv('C:\\Users\\aksha\\Documents\\car_data.csv')
#printing the datas top-bottom
car.head()
#printing the datas bottom-top
car.tail()
# data types
car.dtypes
car.columns
# car.column.values converts pandas to numpy
# analytical summary of the dataset
car.describe(include='all')
# histogram for visualisation
car.hist(figsize=(20,30))
# relationship between 2 variables using sns.boxplot
ax= sns.boxplot(x="engine_size", y="horsepower", data=car)
#swarmplot() to show the datapoints on top of the boxes
ax=sns.swarmplot(x="engine_size", y="horsepower", data=car)
# for understanding pairwise relationships
sns.pairplot(car)
# removing some columns
car=car.drop(['aspiration','wheel_base','length','width','height','peak_rpm','curb_weight','highway_mpg','fuel_system'], axis=1)
car.head()
# rename columns()
car=car.rename(columns={"city_mpg": "mileage","make":"Brand"})
car.head()
# row which contains duplicate data
duplicate_rows_car= car[car.duplicated()]
print("Number of duplicate rows: ", duplicate_rows_car.shape)
car.count()
# removing duplicates if any (there are no duplicates here)
car=car.drop_duplicates()
car.count()
# Droping nan values if any...cleaning data
car=car.dropna()
car.count()
# Finding null values in the data
print(car.isnull().sum())
# finding the outliers
sns.boxplot(x=car['price'])
sns.boxplot(x=car['engine_size'])
#plotting a histogram for number of cars per brand
car.Brand.value_counts().nlargest(40).plot(kind='bar',figsize=(10,5))
plt.title("Number of cars by make")
plt.ylabel("Number of cars")
plt.xlabel("Brand")
# relationship between the variables
c=car.corr()
c
# Corelation using heatmap
# Set up matplotlib figure
f, ax = plt.subplots(figsize=(20, 15))
sns.heatmap(c, cmap='BrBG', square=True,linewidth=.5,annot=True, cbar_kws={"shrink": .5}, ax=ax)