-
Notifications
You must be signed in to change notification settings - Fork 0
/
dataanalysis.py
169 lines (146 loc) · 5.69 KB
/
dataanalysis.py
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
import pandas as pd
import numpy as np
import seaborn as sns
import matplotlib.pyplot as plt
sns.set()
datafile = "clean3.csv"
df = pd.read_csv(datafile)
# =============================================================================
# for elem in range(len(df)):
# try:
# float(df['cylinders'][elem])
# except:
# df['cylinders'][elem] = float(0)
# try:
# float(df['drive'][elem])
# df['drive'][elem] = float(0)
# except:
# pass
#
# df = df.loc[df['cylinders'] != 0]
# df = df.loc[df['drive'] != 0]
#
# df.to_csv("clean2.csv")
# =============================================================================
#df.groupby(['year']).mean().to_csv("year.csv")
byYear = df.sort_values(by=['year'])
data1 = byYear.loc[byYear['year'] <= 2002] #1900-2002
data2 = byYear.loc[byYear['year'] > 2002] #203-2021
# =============================================================================
# #YEAR VS PRICE
# # Add title
# plt.title("Price of Car Based on Year")
#
# # Bar chart showing average arrival delay for Spirit Airlines flights by month
# sns.lineplot(x=data1['year'], y=data1['price'])
#
# # Add label for vertical axis
# plt.ylabel("Price")
# =============================================================================
#DRIVE VS PRICE
# =============================================================================
# #Add title
# plt.title("Price of Car Based on Drive")
#
# # Bar chart showing average arrival delay for Spirit Airlines flights by month
# sns.barplot(x=data2['drive'], y=data2['price'])
#
# # Add label for vertical axis
# plt.ylabel("Price")
# =============================================================================
#CYLINDER VS PRICE
# =============================================================================
# #Add title
# plt.title("Price of Car Based on Cylinders")
#
# # Bar chart showing average arrival delay for Spirit Airlines flights by month
# sns.barplot(x=data2['cylinders'], y=data2['price'])
#
# # Add label for vertical axis
# plt.ylabel("Price")
# =============================================================================
#ODOMETER VS PRICE
# =============================================================================
# # Add title
# plt.title("Price of Car Based on Odometer")
#
# # Bar chart showing average arrival delay for Spirit Airlines flights by month
# sns.lineplot(x=data1['odometer'], y=data1['price'])
#
# # Add label for vertical axis
# plt.ylabel("Price")
# =============================================================================
# =============================================================================
# #COLOR VS PRICE
# # Add title
# plt.title("Average Price of Car Based on Colour")
#
# # Bar chart showing average arrival delay for Spirit Airlines flights by month
# sns.barplot(x=data2['paint_color'], y=data2['price'])
#
# # Add label for vertical axis
# plt.ylabel("Price")
# =============================================================================
# =============================================================================
# #TRANSMISSION VS PRICE
# # Add title
# plt.title("Average Price of Car Based on Transmission")
#
# # Bar chart showing average arrival delay for Spirit Airlines flights by month
# sns.barplot(x=data2['transmission'], y=data2['price'])
#
# # Add label for vertical axis
# plt.ylabel("Price")
# =============================================================================
# =============================================================================
# #ODOMETER VS YEAR
# #Add title
# plt.title("ODOMETER VS YEAR")
#
# # Bar chart showing average arrival delay for Spirit Airlines flights by month
# sns.lineplot(x=data2['year'], y=data2['odometer'])
#
# # Add label for vertical axis
# plt.ylabel("Odometer")
# =============================================================================
# =============================================================================
# #DISTRIBUTION OF COLOR
# colors = data2.pivot_table(index=['paint_color'], aggfunc='size')
# print(colors)
# for i in range(len(colors)):
# print(colors[i])
# print(len(data1))
# colors[i] = (colors[i]/len(data2['paint_color'])) * 100
#
# print(colors)
# =============================================================================
# =============================================================================
# #DISTRIBUTION OF TRANSMISSION
# transmissions = data2.pivot_table(index=['transmission'], aggfunc='size')
# print(transmissions)
# for i in range(len(transmissions)):
# print(transmissions[i])
# transmissions[i] = (transmissions[i]/len(data2['transmission'])) * 100
#
# print(transmissions)
# =============================================================================
# =============================================================================
# #DISTRIBUTION OF DRIVE
# drives = data2.pivot_table(index=['drive'], aggfunc='size')
# print(drives)
# for i in range(len(drives)):
# print(drives[i])
# drives[i] = (drives[i]/len(data2['drive'])) * 100
#
# print(drives)
# =============================================================================
# =============================================================================
# #DISTRIBUTION OF CYLINDER
# cylinders = data2.applymap(str).pivot_table(index=['cylinders'], aggfunc='size')
# print(cylinders)
# for i in range(len(cylinders)):
# print(cylinders[i])
# cylinders[i] = (cylinders[i]/len(data2['cylinders'])) * 100
#
# print(cylinders)
# =============================================================================