SQL Import Excel File to Table Using Python Pandas




[ad_1]

Use python pandas to insert data into an SQL table from an Excel file. This method takes advantage of pandas’ read_excel and to_sql functions to cleanly import data from an Excel file into any SQL database.

Works officially with the following SQL database providers: PostgreSQL, MySQL, Oracle, Microsoft SQL Server and SQLite.

Written tutorial: https://syntaxbytetutorials.com/sql-import-excel-file-to-table-with-python-pandas/

Music: X Ray Vision by Slynk from YouTube audio library

Source


[ad_2]

Comment List

  • SyntaxByte
    January 6, 2021

    How to specify data types: add "from sqlalchemy.types import String, SmallInteger" replacing String and SmallInteger with the types you need.

    Then, do "df.to_sql('people', con=engine, if_exists='replace', index=False, dtype={'First Name': String(length=255),
    'Last Name': String(length=255),
    'Age': SmallInteger, 'Phone Number': String(length=255)})"

    Sorry for not including this in the video, I didn't think it would be a super common need.

  • SyntaxByte
    January 6, 2021

    What should the line be if I'm trying to import the excel file into microsoft sql server?

  • SyntaxByte
    January 6, 2021

    When trying this i unfortunate keep getting an error saying "ModuleNotFoundError: No module named 'MySQLdb'
    ", do you have any ideas on why and even maybe a solution.

  • SyntaxByte
    January 6, 2021

    How to specify data types and how to specify index from Python code only??

  • SyntaxByte
    January 6, 2021

    how to specify the data types please make a video on it

  • SyntaxByte
    January 6, 2021

    Amazing. Thanks!!!

Write a comment