Case Study (autos): Exporting Data

In [38]:
# Importing file

import pandas as pd
import numpy as np

url= "https://archive.ics.uci.edu/ml/machine-learning-databases/autos/imports-85.data"

df= pd.read_csv(url, header = None)


# Adding header to data 

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.columns = headers 

Exporting Data

In [42]:
# Saving data into csv file 'carsinfo.csv'

# To drop the index column while writing the DataFrame into csv file 'carsinfo.csv' : Add -> index=False

df.to_csv('carsinfo.csv' , index = False)
In [43]:
# Reading from csv file 'carsinfo.csv'

df= pd.read_csv('carsinfo.csv')
In [44]:
df
Out[44]:
symboling normalized_losses make fuel_type aspiration num_of_doors body_style drive_wheels engine_location wheel_base ... engine_size fuel_system bore stroke compression_ratio horsepower peak_rpm city_mpg highway_mpg price
0 3 ? alfa-romero gas std two convertible rwd front 88.6 ... 130 mpfi 3.47 2.68 9.0 111 5000 21 27 13495
1 3 ? alfa-romero gas std two convertible rwd front 88.6 ... 130 mpfi 3.47 2.68 9.0 111 5000 21 27 16500
2 1 ? alfa-romero gas std two hatchback rwd front 94.5 ... 152 mpfi 2.68 3.47 9.0 154 5000 19 26 16500
3 2 164 audi gas std four sedan fwd front 99.8 ... 109 mpfi 3.19 3.40 10.0 102 5500 24 30 13950
4 2 164 audi gas std four sedan 4wd front 99.4 ... 136 mpfi 3.19 3.40 8.0 115 5500 18 22 17450
... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...
200 -1 95 volvo gas std four sedan rwd front 109.1 ... 141 mpfi 3.78 3.15 9.5 114 5400 23 28 16845
201 -1 95 volvo gas turbo four sedan rwd front 109.1 ... 141 mpfi 3.78 3.15 8.7 160 5300 19 25 19045
202 -1 95 volvo gas std four sedan rwd front 109.1 ... 173 mpfi 3.58 2.87 8.8 134 5500 18 23 21485
203 -1 95 volvo diesel turbo four sedan rwd front 109.1 ... 145 idi 3.01 3.40 23.0 106 4800 26 27 22470
204 -1 95 volvo gas turbo four sedan rwd front 109.1 ... 141 mpfi 3.78 3.15 9.5 114 5400 19 25 22625

205 rows × 26 columns