cursor.execute(""" CREATE TABLE IF NOT EXISTS test_table ( id INTEGER PRIMARY KEY, name TEXT ); """)
conn.commit() conn.close()
print(f"✅ SQLite DB created at: {db_path}")
import pandas as pd import sqlite3 csv_path=r"C:\Users\Sivadhanya\OneDrive\Desktop\internship\Day-4\swiggy.csv" df=pd.read_csv(csv_path) # === Step 2: Connect to SQLite DB (creates file if it doesn't exist) === db_path = r"C:\Users\Sivadhanya\OneDrive\Desktop\internship\Day-4\swiggy.db" # ← This is where the .db file will be created conn = sqlite3.connect(db_path) cursor = conn.cursor() # Step 3: Create table (adjust types as needed) cursor.execute(""" CREATE TABLE IF NOT EXISTS swiggy_data ( ID INTEGER, Area TEXT, City TEXT, Restaurant TEXT, Price INTEGER, Avg_ratings REAL, Total_ratings INTEGER, Food_type TEXT, Address TEXT, Delivery_time INTEGER ); """)
# Step 4: Insert data into table
for _, row in df.iterrows(): cursor.execute(""" INSERT INTO swiggy_data (ID, Area, City, Restaurant, Price, Avg_ratings, Total_ratings, Food_type, Address, Delivery_time) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?) """, tuple(row)) # Step 5: Commit and close conn.commit() conn.close()
print("Data inserted into SQLite database successfully.")