File size: 1,190 Bytes
4c9a5ed |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
import pandas as pd
import sqlite3
from custom_table import get_dataframe
# Specify the path to your Excel file
# excel_file_path = 'C:\\Users\\rakes\\sql\\table_data.xlsx'
# excel_file_path = "https://huggingface.co/spaces/rakeshkumar1812/text-to-SQL-GenAI-App/tree/main/table_data.xlsx"
# Read the Excel file into a pandas DataFrame
# df = pd.read_excel(excel_file_path, sheet_name='Customer_Data')
df = get_dataframe()
# Display the DataFrame
# print(df.shape)
# print(df.head())
# connect to SQLite3
connection = sqlite3.connect("test_db.db")
# Create a Cursor object to insert Record, Create Table
cursor = connection.cursor()
# Delete the table if already exists the table.
cursor.execute("DROP TABLE IF EXISTS tbl_customer");
# Convert DataFrame to SQL table and insert data
df.to_sql('tbl_customer', connection, if_exists='replace', index=False)
## Display All the records
print('the inserted records are ....')
data = cursor.execute('''
Select CustomerKey,GeographyKey,CustomerAlternateKey,Title,FirstName,
MiddleName,LastName from tbl_customer LIMIT 1''')
for row in data:
print(row)
# Commit changes
connection.commit()
# Close the connection
connection.close()
|