How to transfer a excel into a sql database in python

Viewed 38

I just started studying data science and I'm trying to figure out how to turn excel into a SQL database.

1 Answers

you would need to make a script to populate it like this.`import cs50

import csv
import re

def main():
    # Open SQL database
    creatives_data = cs50.SQL("sqlite:///# the sql file path here")

    # Open csv file
    with open("#the excel file path here", encoding='utf8', errors='ignore') as csvfile:
        source_reader = []
        temp = csv.DictReader(csvfile)
        i = 0
        for row in temp:
            source_reader.insert(i, row)
            i = i + 1

    for row in source_reader:

        creatives_data.execute(
            f"INSERT INTO #the sql table name (#the row name in excel) values (?)", row["OXY"])
main()
Related