Create and Import CSV file into Database

Linkedin’s Industry Codes

import sqlite3, os, csv

conn = sqlite3.connect('industry_classifications')
curs = conn.cursor()

tblcmd = 'create table linkedin_industries (code int(3), groups char(60), description char(60))'
curs = conn.execute('select * from linkedin_industries')
names = [description[0] for description in curs.description]
names
curs.execute(tblcmd)
curs.rowcount

file = r'C:projectsLinkedinIndustry Codes.csv'

with open(file, 'r', encoding='utf-8') as f:
    readCSV = csv.reader(f, delimiter=',')
    for row in readCSV:
        curs.execute('INSERT INTO linkedin_industries (code, groups, description) VALUES (?, ?, ?)', row)


curs.execute('select * from linkedin_industries')

for rec in curs.fetchall():
print(rec)

conn.commit()

Leave a Reply

Your email address will not be published. Required fields are marked *