You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
44 lines
1.3 KiB
44 lines
1.3 KiB
import pandas as pd
|
|
import psycopg2 as psy
|
|
import getpass
|
|
|
|
data = pd. read_csv (r'carDetails.csv')
|
|
df = pd.DataFrame(data)
|
|
df = df.drop_duplicates()
|
|
|
|
co = None
|
|
|
|
try:
|
|
co = psy. connect(host='londres',
|
|
database ='dbanperederi',
|
|
user='anperederi',
|
|
password = getpass.getpass("Mot de passe:"))
|
|
|
|
curs = co.cursor()
|
|
|
|
curs. execute ('''DROP TABLE IF EXISTS Car, Model, Seller ;''')
|
|
|
|
curs. execute ('''CREATE TABLE Car (
|
|
IdCar numeric(10) NOT NULL,
|
|
Model varchar(100) NOT NULL,
|
|
Color numeric(12) NOT NULL,
|
|
Year year NOT NULL,
|
|
Kilometer numeric(10) NOT NULL,
|
|
IdSeller numeric(5) NOT NULL,
|
|
PRIMARY KEY (IdCar)
|
|
);
|
|
''')
|
|
|
|
for row in df.itertuples ():
|
|
curs. execute ('''INSERT INTO Car VALUES (%s ,%s ,%s ,%s, %s ,%s ,%s ,%s, %s ,%s);''',
|
|
(row.Name , row.Platform , row.Year , row.Genre , row.Publisher , row.NA_Sales , row.EU_Sales , row.JP_Sales , row.Other_Sales , row.Global_Sales ))
|
|
|
|
#curs.execute('''UPDATE''')
|
|
|
|
co.commit ()
|
|
curs.close ()
|
|
except (Exception , psy.DatabaseError ) as error :
|
|
print ( error )
|
|
finally :
|
|
if co is not None:
|
|
co.close () |