-
Notifications
You must be signed in to change notification settings - Fork 10
/
10. review.py
31 lines (23 loc) · 879 Bytes
/
10. review.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
import codecademylib3
# Import pandas with alias
import pandas as pd
import numpy as np
# Import dataset as a Pandas Dataframe
auto = pd.read_csv('autos.csv', index_col=0)
# Print the first 10 rows of the auto dataset
print(auto.head(10))
# Print the data types of the auto dataframe
print(auto.dtypes)
# Change the data type of price to float
auto['price'] = auto['price'].astype('float')
print(auto.dtypes)
# Set the engine_size data type to category
auto['engine_size'] = pd.Categorical(auto['engine_size'], ['small','medium','large'], ordered=True)
print(auto['engine_size'].unique())
# Create the engine_codes variable by encoding engine_size
auto['engine_codes'] = auto['engine_size'].cat.codes
print(auto.head())
# One-Hot Encode the body-style variable
auto = pd.get_dummies(auto, columns = ['body-style'])
# Check the order of the type column
print(auto.head())