-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathread_csv_file.py
More file actions
66 lines (53 loc) · 1.47 KB
/
Copy pathread_csv_file.py
File metadata and controls
66 lines (53 loc) · 1.47 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
import pandas as pd
# The direct link to the data file is this:
url = "https://archive.ics.uci.edu/ml/machine-learning-databases/autos/imports-85.data"
# Read the CSV file into a DataFrame from URL
df_url = pd.read_csv(url, header=None)
# Read the CSV file into a DataFrame from .csv file
df_local = pd.read_csv("data/01_automobile_dataset.csv", header=None)
# Display the first 5 rows of both DataFrames without headers
print("From URL (without headers):")
print(df_url.head(5))
print("\nFrom Local File (without headers):")
print(df_local.head(5))
# Define the headers
headers = [
"symboling",
"normalized-losses",
"make",
"fuel-type",
"aspiration",
"num-of-doors",
"body-style",
"drive-wheels",
"engine-location",
"wheel-base",
"length",
"width",
"height",
"curb-weight",
"engine-type",
"num-of-cylinders",
"engine-size",
"fuel-system",
"bore",
"stroke",
"compression-ratio",
"horsepower",
"peak-rpm",
"city-mpg",
"highway-mpg",
"price",
]
df_url.columns = headers
df_local.columns = headers
# Display the first 5 and last 5 rows of both DataFrames with headers
print("From URL (with headers):")
print(df_url.head(5))
print("\nFrom Local File (with headers):")
print(df_local.head(5))
# Save the DataFrame with headers to a new CSV file
df_local.to_csv(
"data/02_automobile_dataset_with_header.csv",
index=False,
)