-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcodecars
More file actions
33 lines (25 loc) · 833 Bytes
/
codecars
File metadata and controls
33 lines (25 loc) · 833 Bytes
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
frame = pd.read_csv('mtcars.csv')
print(frame)
frame.set_index('Car Name', inplace=True)
print(frame)
frame = pd.DataFrame(frame, columns=["cyl","gear","hp","mpg"])
frame.columns = ["Cylinders", "Gear","Horsepower","Miles per Gallon"]
print(frame)
frame['Powerful'] = frame["Horsepower"] >=110
print(frame)
df2 = frame.copy()
# use either del or drop.
# del df2['Horsepower']
df2 = df2.drop('Horsepower', axis=1)
print(df2)
frame2 = (frame[frame["Miles per Gallon"]>25].sort_values(by=["Horsepower"], ascending=False))
print(frame2)
new = frame[frame["Powerful"] == True]
new[new["Miles per Gallon"] == new["Miles per Gallon"].max()]
# # solution 2
df = frame[frame['Powerful']==True]
column = df['Miles per Gallon']
# print(column)
max_value = column.max()
# print(max_value)
print(df[df['Miles per Gallon'] == max_value])