0% found this document useful (0 votes)
25 views4 pages

Untitled - Ipynb - (5) - JupyterLab

The document involves data analysis of an automobile dataset using pandas in Python. Key findings include the average car price of approximately $13,207, the cheapest make being Subaru, and the costliest make being Mercedes-Benz. Additionally, it identifies 90 cars with horsepower greater than 100 and lists the top three car makes by frequency.

Uploaded by

neeru.kum22
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
25 views4 pages

Untitled - Ipynb - (5) - JupyterLab

The document involves data analysis of an automobile dataset using pandas in Python. Key findings include the average car price of approximately $13,207, the cheapest make being Subaru, and the costliest make being Mercedes-Benz. Additionally, it identifies 90 cars with horsepower greater than 100 and lists the top three car makes by frequency.

Uploaded by

neeru.kum22
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

In [ ]:

In [30]: import pandas as pd

In [31]: auto = pd.read_csv('Automobile.csv')

In [ ]: # answer 1

In [33]: auto.info()

<class 'pandas.core.frame.DataFrame'>
RangeIndex: 201 entries, 0 to 200
Data columns (total 26 columns):
# Column Non-Null Count Dtype
--- ------ -------------- -----
0 symboling 201 non-null int64
1 normalized_losses 201 non-null int64
2 make 201 non-null object
3 fuel_type 201 non-null object
4 aspiration 201 non-null object
5 number_of_doors 201 non-null object
6 body_style 201 non-null object
7 drive_wheels 201 non-null object
8 engine_location 201 non-null object
9 wheel_base 201 non-null float64
10 length 201 non-null float64
11 width 201 non-null float64
12 height 201 non-null float64
13 curb_weight 201 non-null int64
14 engine_type 201 non-null object
15 number_of_cylinders 201 non-null object
16 engine_size 201 non-null int64
17 fuel_system 201 non-null object
18 bore 201 non-null float64
19 stroke 201 non-null float64
20 compression_ratio 201 non-null float64
21 horsepower 201 non-null int64
22 peak_rpm 201 non-null int64
23 city_mpg 201 non-null int64
24 highway_mpg 201 non-null int64
25 price 201 non-null int64
dtypes: float64(7), int64(9), object(10)
memory usage: 41.0+ KB

In [ ]: # answer 3

In [35]: average_price = auto['price'].mean()

In [36]: print(f"the average price of all cars is:{average_price}")

the average price of all cars is:13207.129353233831

In [37]: cheapest_make = auto.loc[auto['price'].idxmin()]['make']

In [40]: costliest_make = auto.loc[auto['price'].idxmax()]['make']


In [41]: print(f"The cheapest make is :{cheapest_make}")

The cheapest make is :subaru

In [42]: print(f"The costliest make is :{costliest_make}")

The costliest make is :mercedes-benz

In [43]: cars_with_high_hp = auto[auto['horsepower'] > 100]

In [44]: num_cars_with_high_hp = cars_with_high_hp.shape[0]

In [45]: print(f'Number of cars with horsepower greater than 100 :{num_cars_with_high_hp}

Number of cars with horsepower greater than 100 :90

In [48]: print(auto.info())

<class 'pandas.core.frame.DataFrame'>
RangeIndex: 201 entries, 0 to 200
Data columns (total 26 columns):
# Column Non-Null Count Dtype
--- ------ -------------- -----
0 symboling 201 non-null int64
1 normalized_losses 201 non-null int64
2 make 201 non-null object
3 fuel_type 201 non-null object
4 aspiration 201 non-null object
5 number_of_doors 201 non-null object
6 body_style 201 non-null object
7 drive_wheels 201 non-null object
8 engine_location 201 non-null object
9 wheel_base 201 non-null float64
10 length 201 non-null float64
11 width 201 non-null float64
12 height 201 non-null float64
13 curb_weight 201 non-null int64
14 engine_type 201 non-null object
15 number_of_cylinders 201 non-null object
16 engine_size 201 non-null int64
17 fuel_system 201 non-null object
18 bore 201 non-null float64
19 stroke 201 non-null float64
20 compression_ratio 201 non-null float64
21 horsepower 201 non-null int64
22 peak_rpm 201 non-null int64
23 city_mpg 201 non-null int64
24 highway_mpg 201 non-null int64
25 price 201 non-null int64
dtypes: float64(7), int64(9), object(10)
memory usage: 41.0+ KB
None

In [55]: top_cars = auto['make'].value_counts().head(3)

In [56]: print(top_cars)
toyota 32
nissan 18
mazda 17
Name: make, dtype: int64

In [59]: car = auto[auto['price'] == 7099]

In [61]: print(car['make'])

87 nissan
Name: make, dtype: object

In [64]: cars_above_40000 = auto[auto['price'] > 40000]

In [ ]:

In [65]: print(cars_above_40000)

symboling normalized_losses make fuel_type aspiration \


15 0 149 bmw gas std
70 0 140 mercedes-benz gas std
71 1 140 mercedes-benz gas std

number_of_doors body_style drive_wheels engine_location wheel_base ... \


15 two sedan rwd front 103.5 ...
70 four sedan rwd front 120.9 ...
71 two hardtop rwd front 112.0 ...

engine_size fuel_system bore stroke compression_ratio horsepower \


15 209 mpfi 3.62 3.39 8.0 182
70 308 mpfi 3.80 3.35 8.0 184
71 304 mpfi 3.80 3.35 8.0 184

peak_rpm city_mpg highway_mpg price


15 5400 16 22 41315
70 4500 14 16 40960
71 4500 14 16 45400

[3 rows x 26 columns]

In [ ]: # answer 10

In [78]: sedan_7000 = auto[(auto['body_style'] == 'sedan') & (auto['price'] < 7000)]

In [80]: print(sedan_7000)
symboling normalized_losses make fuel_type aspiration \
19 0 81 chevrolet gas std
24 1 148 dodge gas std
42 0 110 isuzu gas std
50 1 113 mazda gas std
82 1 125 mitsubishi gas std
86 1 128 nissan gas std
88 1 128 nissan gas std
89 1 122 nissan gas std
118 1 154 plymouth gas std
152 0 91 toyota gas std

number_of_doors body_style drive_wheels engine_location wheel_base ... \


19 four sedan fwd front 94.5 ...
24 four sedan fwd front 93.7 ...
42 four sedan rwd front 94.3 ...
50 four sedan fwd front 93.1 ...
82 four sedan fwd front 96.3 ...
86 two sedan fwd front 94.5 ...
88 two sedan fwd front 94.5 ...
89 four sedan fwd front 94.5 ...
118 four sedan fwd front 93.7 ...
152 four sedan fwd front 95.7 ...

engine_size fuel_system bore stroke compression_ratio horsepower \


19 90 2bbl 3.03 3.11 9.6 70
24 90 2bbl 2.97 3.23 9.4 68
42 111 2bbl 3.31 3.23 8.5 78
50 91 2bbl 3.03 3.15 9.0 68
82 122 2bbl 3.35 3.46 8.5 88
86 97 2bbl 3.15 3.29 9.4 69
88 97 2bbl 3.15 3.29 9.4 69
89 97 2bbl 3.15 3.29 9.4 69
118 90 2bbl 2.97 3.23 9.4 68
152 98 2bbl 3.19 3.03 9.0 70

peak_rpm city_mpg highway_mpg price


19 5400 38 43 6575
24 5500 31 38 6692
42 4800 24 29 6785
50 5000 31 38 6695
82 5000 25 32 6989
86 5200 31 37 5499
88 5200 31 37 6649
89 5200 31 37 6849
118 5500 31 38 6692
152 4800 30 37 6938

[10 rows x 26 columns]

In [ ]:

You might also like